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);
相关推荐
球球pick小樱花2 小时前
游戏官网前端工具库:海内外案例解析
前端·javascript·css
喝水的长颈鹿2 小时前
【大白话前端 02】网页从解析到绘制的全流程
前端·javascript
明君879972 小时前
Flutter 实现 AI 聊天页面 —— 记一次 Markdown 数学公式显示的踩坑之旅
前端·flutter
用户14536981458783 小时前
VersionCheck.js - 让前端版本更新变得简单优雅
前端·javascript
codingWhat3 小时前
整理「祖传」代码,就是在开发脚手架?
前端·javascript·node.js
码路飞3 小时前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
Lee川3 小时前
优雅进化的JavaScript:从ES6+新特性看现代前端开发范式
javascript·面试
初次攀爬者3 小时前
RocketMQ在Spring Boot上的基础使用
java·spring boot·rocketmq
花花无缺3 小时前
搞懂@Autowired 与@Resuorce
java·spring boot·后端
颜酱3 小时前
单调队列:滑动窗口极值问题的最优解(通用模板版)
javascript·后端·算法