public static String makeSig() throws Exception {
String secret = "12345678abcdefgh1234&";
Mac mac = Mac.getInstance("HmacSHA1");
SecretKeySpec secretKey = new SecretKeySpec(
secret.getBytes(UTF_8), mac.getAlgorithm());
mac.init(secretKey);
String mk = "testtest";
byte[] hash = mac.doFinal(mk.getBytes(UTF_8));
String sign = Base64.encodeToString(hash, Base64.NO_WRAP);
Log.d("Test", "makeSig: "+sign);
return sign;
}
请参考官网案例,消息认证码计算:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/crypto-compute-mac-V5