为什么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);