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);
相关推荐
漂流瓶jz2 小时前
总结CSS组件化演进之路:命名规范/CSS Modules/CSS in JS/原子化CSS
前端·javascript·css
budingxiaomoli3 小时前
Spring IoC &DI
java·spring·ioc·di
Spider Cat 蜘蛛猫3 小时前
Springboot SSO系统设计文档
java·spring boot·后端
未若君雅裁3 小时前
MySQL高可用与扩展-主从复制读写分离分库分表
java·数据库·mysql
学习中.........3 小时前
从扰动函数的变化,感受红黑树带来的性能提升
java
steven~~~4 小时前
为什么mq报错
javascript
计算机安禾4 小时前
【c++面向对象编程】第24篇:类型转换运算符:自定义隐式转换与explicit
java·c++·算法
weixin199701080164 小时前
【保姆级教程】淘宝/天猫商品详情 API(item_get)接入指南:Python/Java/PHP 调用示例与 JSON 返回值解析
java·python·php
环流_4 小时前
redis核心数据类型在java中的操作
java·数据库·redis
雨辰AI5 小时前
SpringBoot3 项目国产化改造完整流程|从 MySQL 到人大金仓落地
java·数据库·后端·mysql·政务