aesEncrypt static method

dynamic aesEncrypt(
  1. String plainStr,
  2. String keyStr, {
  3. required String ivStr,
})

AES加密 ivStr 偏移量 ecb 模式不需要 http://tool.chacuo.net/cryptaes

Implementation

static aesEncrypt(String plainStr, String keyStr, {required String ivStr}) {
  try {
    final key = encrypt.Key.fromUtf8(keyStr);
    final iv = encrypt.IV.fromUtf8(ivStr);
    final encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));
    final encrypted = encrypter.encrypt(plainStr, iv: iv);
    return encrypted.base64;
  } catch (err) {
    print("aes encode error:$err");
    return plainStr;
  }
}