簡體   English   中英

Dart 使用 Base64 編碼十六進制

[英]Dart encoding hex using Base64

我需要對此進行編碼

“f08b3616d575acffc9c9493a888eb4f915a6830f94101363ba01fc7c42011789”

對此

"8Is2FtV1rP/JyUk6iI60+RWmgw+UEBNjugH8fEIBF4k="

使用 dart 和 base64 編碼。 我用這個工具base64 編碼

細節

如果有幫助,我可以使用這個 oneliner 在 Python 上做到這一點

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

但不知道 dart 中的等效項

十六進制編解碼器不在核心dart:convert中,而是埋在 package 中,也稱為convert 因此,將convert添加到您的pubspec.yaml ,然后:

import 'dart:convert';

import 'package:convert/convert.dart';

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM