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);
相关推荐
子兮曰5 小时前
OpenClaw架构揭秘:178k stars的个人AI助手如何用Gateway模式统一控制12+通讯频道
前端·javascript·github
百锦再6 小时前
Reactive编程入门:Project Reactor 深度指南
前端·javascript·python·react.js·django·前端框架·reactjs
百锦再6 小时前
React编程高级主题:测试代码
android·前端·javascript·react.js·前端框架·reactjs
JH30736 小时前
SpringBoot 优雅处理金额格式化:拦截器+自定义注解方案
java·spring boot·spring
颜酱7 小时前
图结构完全解析:从基础概念到遍历实现
javascript·后端·算法
Coder_Boy_7 小时前
技术让开发更轻松的底层矛盾
java·大数据·数据库·人工智能·深度学习
invicinble8 小时前
对tomcat的提供的功能与底层拓扑结构与实现机制的理解
java·tomcat
小迷糊的学习记录8 小时前
Vuex 与 pinia
前端·javascript·vue.js
发现一只大呆瓜8 小时前
前端性能优化:图片懒加载的三种手写方案
前端·javascript·面试
较真的菜鸟8 小时前
使用ASM和agent监控属性变化
java