aesEncrypt function

String aesEncrypt(
  1. String plainText,
  2. String key
)

Implementation

String aesEncrypt(String plainText, String key) {
  final keyBytes = utf8.encode(key);
  final paddedKey = Uint8List.fromList(List<int>.from(keyBytes)
    ..addAll(List<int>.filled(32 - keyBytes.length, 0)));
  final encrypterKey = encrypt.Key(paddedKey);
  final iv = encrypt.IV(Uint8List.fromList(List<int>.filled(16, 0)));
  final encrypter = encrypt.Encrypter(encrypt.AES(encrypterKey));

  final encrypted = encrypter.encrypt(plainText, iv: iv);
  return base64.encode(encrypted.bytes);
}