aesEncrypt(cipher, txt) {
final key = Key(cipher);
// final iv = IV(seed(16));
// I set this to fixed to reduce complex, will change to above line code when in prod
final iv = IV.fromBase64('Qj7t3X7hmoMU+UuS8vccjQ==');
final encrypter = Encrypter(AES(key));
final encrypted = encrypter.encrypt(txt, iv: iv);
Uint8List ctbuf = encrypted.bytes;
print('keybuf:$cipher');
print('ctbuf:$ctbuf');
Uint8List ivBuf = iv.bytes;
print('ivBuf的base64编码:${base64Encode(ivBuf)}');
print('ivBuf:$ivBuf');
String bytesAll = base64Encode(NanoHelpers.concat([ivBuf, ctbuf]));
// print('dart端加密出的密文:$bytesAll');
return bytesAll;
}
aesDecrypt(cipher, enc) {
final key = Key(cipher);
Uint8List bufAll = base64Decode(enc);
final iv = IV(bufAll.sublist(0, 16));
final encrypter = Encrypter(AES(key));
final decrypted = encrypter.decrypt(Encrypted(bufAll.sublist(16)), iv: iv);
// print(decrypted);
return decrypted;
}
test.dart
aescbc.dart
if I change
final encrypter = Encrypter(AES(key))
tofinal encrypter = Encrypter(AES(key, mode: AESMode.cbc));
the title error will occur