hmac生成码
private static String sha256_HMAC(String message, byte[] secret) {
String hash = "";
try {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(secret, "HmacSHA256");
sha256_HMAC.init(secret_key);
byte[] bytes = sha256_HMAC.doFinal(message.getBytes(StandardCharsets.UTF_8));
hash = new String(java.util.Base64.getEncoder().encode(bytes), StandardCharsets.UTF_8);
System.out.println(hash);
} catch (Exception e) {
System.out.println("Error HmacSHA256 ===========" + e.getMessage());
}
return hash;
}
md5加密
@Test
public void genreateMd5() {
String message = "chenrui";
String salt = "chenrui";
String key = "key";
String sign = DigestUtils.md5Hex(message+salt+key);
System.out.println(sign);
}