简体   繁体   中英

Dart encoding hex using Base64

I need to encode this

"f08b3616d575acffc9c9493a888eb4f915a6830f94101363ba01fc7c42011789"

to this

"8Is2FtV1rP/JyUk6iI60+RWmgw+UEBNjugH8fEIBF4k="

using dart and base64 encode. I used this tool base64 encode

细节

If it helps I manage to do it on Python using this oneliner

s = codecs.encode(codecs.decode(hex, 'hex'), 'base64').decode()

but have no clue for the equivalent in dart

The hex codec isn't in the core dart:convert but is buried in a package also called convert . So, add convert to your pubspec.yaml , and then:

import 'dart:convert';

import 'package:convert/convert.dart';

void main() {
  final h = 'f08b3616d575acffc9c9493a888eb4f915a6830f94101363ba01fc7c42011789';
  final b = base64.encode(hex.decode(h));
  print(b);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM