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);
相关推荐
阡陌数智22 分钟前
Claude API新版本重大变更与安全升级指南
java·linux·安全
学长毕设2 小时前
基于SpringBoot的野生动物公益保护平台设计与实现-附源码
java·spring boot·后端
SL_staff3 小时前
离散制造排程破局:JVS-APS 四步闭环落地实践(开发者视角)
java·产品·全栈
这个昵称不容易3 小时前
SpringBoot 美容院管理系统:232个Java文件315个接口,5套角色从预约到发货一整条链路
java·springboot·毕设
装不满的克莱因瓶4 小时前
【SpringAI Alibaba】ReactAgent记忆管理MessageTrimmingHook与MessageDeletionHook
java·人工智能·ai·ai编程·springai·springaialibaba
文丑颜不良啊4 小时前
LeetCode2241~2260题目解析
java·leetcode
文丑颜不良啊4 小时前
LeetCode2321~2340题目解析
java·leetcode
vipxieliang4 小时前
JavaScript 迭代器与生成器:控制异步与惰性求值
前端·javascript
驭渊的小故事4 小时前
Spring AOP 核心概念与通知类型详解
java·后端·spring
vipxieliang4 小时前
ValidX vs 手写验证代码:开发效率对比实测
java·spring boot·后端