Flutter:encrypt插件 AES加密处理
1、pubspec.yaml导入插件
cupertino_icons: ^1.0.8
# 密码加密
encrypt: 5.0.3
encrypt封装
import 'package:encrypt/encrypt.dart';
/// 加密类
class EncryptUtil {
static final EncryptUtil _instance = EncryptUtil._internal();
factory EncryptUtil() => _instance;
EncryptUtil._internal() {
encrypter = Encrypter(AES(
key,
mode: AESMode.cbc,
padding: 'PKCS7',
));
}
final key = Key.fromUtf8('aH5aH5bG0dC6aA3oN0cK4aU5jU6aK2lN');
final iv = IV.fromUtf8('hK6eB4aE1aF3gH5q');
late Encrypter encrypter;
/// aes加密
String aesEncode(String content) {
final encrypted = encrypter.encrypt(content, iv: iv);
return encrypted.base64;
}
}
页面中使用
// 加密后
var password = EncryptUtil().aesEncode(passwordController.text);
原文地址:https://blog.csdn.net/qq_40745143/article/details/144084737
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!