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);