import 'dart:convert';
import 'package:encrypt/encrypt.dart' as enc;

/// AES/ECB/PKCS5Padding 加密
String aesEncryptEcbPkcs5({
  required String plainText,
   String keyUtf8="daac3ae52eff4cec",
}) {
  final key = enc.Key.fromUtf8(keyUtf8);
  final encrypter = enc.Encrypter(enc.AES(
    key,
    mode: enc.AESMode.ecb,
    padding: 'PKCS7', // Dart里用PKCS7，对齐Java的PKCS5
  ));
  final encrypted = encrypter.encrypt(plainText);
  return encrypted.base64;
}

/// AES/ECB/PKCS5Padding 解密
String aesDecryptEcbPkcs5({
  required String cipherBase64,
  required String keyUtf8,
}) {
  final key = enc.Key.fromUtf8(keyUtf8);
  final encrypter = enc.Encrypter(enc.AES(
    key,
    mode: enc.AESMode.ecb,
    padding: 'PKCS7',
  ));
  final decrypted = encrypter.decrypt(enc.Encrypted.fromBase64(cipherBase64));
  return decrypted;
}