|
@@ -10,6 +10,7 @@ import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
/**
|
|
/**
|
|
* hmac签名
|
|
* hmac签名
|
|
|
|
+ *
|
|
* @Author:caozj
|
|
* @Author:caozj
|
|
* @DATE:2022/7/27 19:51
|
|
* @DATE:2022/7/27 19:51
|
|
*/
|
|
*/
|
|
@@ -22,7 +23,7 @@ public class HmacUtil {
|
|
* HmacSHA256加密
|
|
* HmacSHA256加密
|
|
*
|
|
*
|
|
* @param input 需要加密得参数
|
|
* @param input 需要加密得参数
|
|
- * @param key 密钥
|
|
|
|
|
|
+ * @param key 密钥
|
|
* @return 加密后的值
|
|
* @return 加密后的值
|
|
**/
|
|
**/
|
|
public static String encrypt(String input, String key) {
|
|
public static String encrypt(String input, String key) {
|
|
@@ -48,7 +49,7 @@ public class HmacUtil {
|
|
/**
|
|
/**
|
|
* byte数组转16进制字符串
|
|
* byte数组转16进制字符串
|
|
*
|
|
*
|
|
- * @param bytes byte数组
|
|
|
|
|
|
+ * @param bytes byte数组
|
|
* @return hex字符串
|
|
* @return hex字符串
|
|
*/
|
|
*/
|
|
public static String bytesToHexStr(byte[] bytes) {
|
|
public static String bytesToHexStr(byte[] bytes) {
|
|
@@ -62,9 +63,5 @@ public class HmacUtil {
|
|
}
|
|
}
|
|
return hexStr.toString();
|
|
return hexStr.toString();
|
|
}
|
|
}
|
|
- public static void main(String[] args) {
|
|
|
|
- System.out.println(System.currentTimeMillis());
|
|
|
|
- String valSha256 = HmacUtil.encrypt("fjhx"+ System.currentTimeMillis(), "fjhx@2012");
|
|
|
|
- System.out.println(valSha256);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
}
|
|
}
|