当前业务需要使用HmacSHA256编码,根据文档开发
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/crypto-compute-mac-V5\#开发步骤
发现此算法针对不同文本得到的加密值相同,希望提供有效HmacSHA256编码
附其他系统实现:
public static String hmac(String msg, String secret) {
String hash = "";
try {
Mac sha256mac = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(),"HmacSHA256");
sha256mac.init(secretKey);
hash = HexUtils.toHexString(sha256mac.doFinal(msg.getBytes()));
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
e.printStackTrace();
}
return hash;
}
请参考示例如下: