美文网首页Flutterflutter
Flutter之AES加解密

Flutter之AES加解密

作者: 小杰杰杰 | 来源:发表于2020-07-10 20:42 被阅读0次

    网上搜索到的这个解决方案实在是太烂了
    https://blog.csdn.net/u013685695/article/details/101528438

    https://pub.dev/packages/flutter_aes_ecb_pkcs5

    上边的解决方案是与原生做个bridge,使用原生来加解密。

    其实直接用Dart原生就行
    https://pub.dev/packages/encrypt

    上代码

    import 'package:encrypt/encrypt.dart' as XYQ;
    
    void main() {
      final key = XYQ.Key.fromUtf8('my 32 length key................');
      final encrypter = XYQ.Encrypter(XYQ.AES(key, mode: XYQ.AESMode.ecb));
      final text =
          "A set of high-level APIs over PointyCastle for two-way cryptography.";
      final encrypted = encrypter.encrypt(text);
      final decrypted = encrypter.decrypt(encrypted);
    
      print(
          decrypted); // A set of high-level APIs over PointyCastle for two-way cryptography.
      print(encrypted
          .base64); // +H8VseqZhaZaK8EUh+K2jlHXBFbRA/dHkpPDf0fN+YaNro9ofBNlLsVtrkmmiulBoBiS4EQE7djVvsouuVyIXwe3lQogMzWcdAULNBSrSRM=
    }
    

    相关文章

      网友评论

        本文标题:Flutter之AES加解密

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