Commit b6e68837 authored by 张永's avatar 张永

Merge branch 'master' of http://gitlab.egolm.com/key/common.git

parents b4be8a39 c4d623d0
......@@ -926,6 +926,18 @@ public class StringUtil {
}
}
public static String toHMACSHA256String(String encryptText, String encryptKey) {
try {
SecretKey secretKey = new SecretKeySpec(encryptKey.getBytes(), "HmacSHA256");
Mac mac = Mac.getInstance(secretKey.getAlgorithm());
mac.init(secretKey);
byte[] bs = mac.doFinal(encryptText.getBytes());
return Base64.encodeBase64String(bs);
} catch (Exception e) {
throw new SHA1Exception(e);
}
}
public static String toMD5HexString(String text) {
try {
return StringUtil.encodeHexString(MessageDigest.getInstance("MD5").digest(text.getBytes())).toUpperCase();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment