Dart – Encode and decode base64 string

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

Leave a Comment