美文网首页Flutter
flutter AESUtil 加密 cbc

flutter AESUtil 加密 cbc

作者: 一个半吊子工程师 | 来源:发表于2020-07-20 14:13 被阅读0次
import 'package:encrypt/encrypt.dart';

class AESUtil {
  static String generateAES(String data, String keyStr, String ivStr) {
    final plainText = data;
    final key = Key.fromUtf8(keyStr);
    final iv = IV.fromUtf8(ivStr);
    final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
    final encrypted = encrypter.encrypt(plainText, iv: iv);
//    final decrypted = encrypter.decrypt(encrypted, iv: iv);

//    print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elit
    print(encrypted.base64); // R4PxiU3h8YoIRq
    return encrypted.base64;
  }
}

简单使用

  var password = AESUtil.generateAES(
        '123456', 'your keyStr', 'your ivStr');//your keyStr 如0123456776543210

相关文章

网友评论

    本文标题:flutter AESUtil 加密 cbc

    本文链接:https://www.haomeiwen.com/subject/bpaekktx.html