Flutter:encrypt插件 AES加密处理

1、pubspec.yaml导入插件

复制代码
cupertino_icons: ^1.0.8
# 密码加密
encrypt: 5.0.3

encrypt封装

js 复制代码
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;
  }
}

页面中使用

js 复制代码
// 加密后
var password = EncryptUtil().aesEncode(passwordController.text);
相关推荐
芙莉莲教你写代码几秒前
Flutter 框架跨平台鸿蒙开发 - 音乐节拍器应用
flutter
疯狂打码的少年2 分钟前
【Day 6 Java转Python】字符串处理的“降维打击”
java·开发语言·python
芙莉莲教你写代码2 分钟前
Flutter 框架跨平台鸿蒙开发 - 气泡消除游戏
flutter·游戏·华为·harmonyos
EFCY1MJ9021 分钟前
MYSQL ID耗尽应急恢复方案
java·数据库·mysql
hogenlaw32 分钟前
Stream流
android·java·开发语言
. . . . .36 分钟前
抽象语法树 AST
javascript
zero15971 小时前
TypeScript 快速实战系列:基础入门|TypeScript 核心语法 1 小时吃透(必备基础)
javascript·typescript·大模型编程语言
pl4H522a62 小时前
Python 高效实现 Excel 转 TXT 文本
java·python·excel
稻草猫.2 小时前
Spring事务操作全解析
java·数据库·后端·spring
她说..2 小时前
Java 基本数据类型高频面试题
java·开发语言·jvm·spring boot