How to native convert string -> base64 and base64 -> string

后端 未结 4 1360
执笔经年
执笔经年 2020-11-28 15:46

How to native convert string -> base64 and base64 -> string

I\'m find only this bytes to base64string

would like this:

4条回答
  •  死守一世寂寞
    2020-11-28 16:11

    As of 0.9.2 of the crypto package

    CryptoUtils is deprecated. Use the Base64 APIs in dart:convert and the hex APIs in the convert package instead.

    import 'dart:convert' show utf8, base64;
    
    main() {
      final str = 'https://dartpad.dartlang.org/';
    
      final encoded = base64.encode(UTF8.encode(str));
      print('base64: $encoded');
    
      final str2 = utf8.decode(base64.decode(encoded));
      print(str2);
      print(str == str2);
    }
    

    Try it in DartPad

提交回复
热议问题