import 'package:encrypt/encrypt.dart';
class AESUtil {
static String generateAES(String data, String keyStr, String ivStr) {
final plainText = data;
final key = Key.fromUtf8(keyStr);
final iv = IV.fromUtf8(ivStr);
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
final encrypted = encrypter.encrypt(plainText, iv: iv);
// final decrypted = encrypter.decrypt(encrypted, iv: iv);
// print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elit
print(encrypted.base64); // R4PxiU3h8YoIRq
return encrypted.base64;
}
}
简单使用
var password = AESUtil.generateAES(
'123456', 'your keyStr', 'your ivStr');//your keyStr 如0123456776543210
网友评论