如何用 flutter 实现 js 中的 aes 加密?
在 flutter 项目中,想要实现 js 中的 aes 加密,可以借助第三方库 encrypt。这是一个专门用于加密和解密的库,它提供了 aes 加密所需的函数。
以下是如何用 encrypt 库来实现 js 中的 aes 加密:
- import 'package:encrypt/encrypt.dart';encryptAes( String plainText, ) { // AES 密钥和 IV const key = 'ihaierForTodoKey'; const iv = 'ihaierForTodo_Iv'; // 创建密钥和 IV final _key = Key.fromUtf8(key); final _iv = IV.fromUtf8(iv); // 创建 AES 加密器 final encrypter = Encrypter(AES(_key, mode: AESMode.cbc)); // 加密 final encrypted = encrypter.encrypt(plainText, iv: _iv); // 返回 base64 编码的密文 return encrypted.base64; }
登录后复制
以上就是Flutter 如何实现 JS 中的 AES 加密?的详细内容,更多请关注【创想鸟】其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。