encryptVal function

String encryptVal(
  1. String plaintextStr,
  2. String encKey
)

A function for ecrypting a plaintext value

Takes the arguments plaintext value and the encryption key and returns a string of the encrypted value. Note: AES encryption is used in this function. For more details see: https://en.wikipedia.org/wiki/Advanced_Encryption_Standard

Implementation

String encryptVal(String plaintextStr, String encKey) {
  String encKeySha256 =
      sha256.convert(utf8.encode(encKey)).toString().substring(0, 32);
  final keyEncode = Key.fromUtf8(encKeySha256);
  final encrypter = Encrypter(AES(keyEncode, mode: AESMode.cbc));
  final encryptVal = encrypter.encrypt(plaintextStr, iv: getDummyIv());
  String encryptValStr = encryptVal.base64.toString();
  return encryptValStr;
}