为什么sha256的结果与

时间:2019-01-18 05:59:12

标签: dart flutter

为什么Java sha256结果与Dart sha256结果不同?

Dart代码

var key = utf8.encode("Message");
var bytes = utf8.encode("secret");


var hmacSha256 = new Hmac(sha256, key); // HMAC-SHA256
var digest = hmacSha256.convert(bytes);

var result = base64Encode(digest.bytes);

Java代码:      字符串秘密=“秘密”;      字符串message =“ Message”;

 Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
 SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
  sha256_HMAC.init(secret_key);

  byte[] bytes = sha256_HMAC.doFinal(message.getBytes());
  String result = bytesToBase64String(bytes);

0 个答案:

没有答案