mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
add SM4CMAC
This commit is contained in:
parent
77d3015bc0
commit
4cee569d22
@ -12,6 +12,7 @@
|
||||
* 【core 】 ZipWriter增加add方法重载
|
||||
* 【core 】 IterUtil增加filtered,增加FilterIter(issue#2228)
|
||||
* 【core 】 增加NodeListIter、ResettableIter
|
||||
* 【crypto 】 HmacAlgorithm增加SM4CMAC(issue#2206@Github)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 IdcardUtil#getCityCodeByIdCard位数问题(issue#2224@Github)
|
||||
|
@ -3,17 +3,19 @@ package cn.hutool.crypto.digest;
|
||||
/**
|
||||
* HMAC算法类型<br>
|
||||
* see: https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#Mac
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public enum HmacAlgorithm {
|
||||
HmacMD5("HmacMD5"),
|
||||
HmacSHA1("HmacSHA1"),
|
||||
HmacSHA256("HmacSHA256"),
|
||||
HmacSHA384("HmacSHA384"),
|
||||
HmacMD5("HmacMD5"),
|
||||
HmacSHA1("HmacSHA1"),
|
||||
HmacSHA256("HmacSHA256"),
|
||||
HmacSHA384("HmacSHA384"),
|
||||
HmacSHA512("HmacSHA512"),
|
||||
/** HmacSM3算法实现,需要BouncyCastle库支持 */
|
||||
HmacSM3("HmacSM3");
|
||||
HmacSM3("HmacSM3"),
|
||||
/** SM4 CMAC模式实现,需要BouncyCastle库支持 */
|
||||
SM4CMAC("SM4CMAC");
|
||||
|
||||
private final String value;
|
||||
|
||||
@ -24,4 +26,4 @@ public enum HmacAlgorithm {
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,4 +83,18 @@ public class HmacTest {
|
||||
String macHex1 = mac.digestHex(testStr);
|
||||
Assert.assertEquals("d9ad618357c1bfb1d9d1200a763d5eaa", macHex1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sm4CMACTest(){
|
||||
// https://github.com/dromara/hutool/issues/2206
|
||||
final byte[] key = new byte[16];
|
||||
HMac mac = new HMac(HmacAlgorithm.SM4CMAC,
|
||||
KeyUtil.generateKey("SM4", key));
|
||||
|
||||
// 原文
|
||||
String testStr = "test中文";
|
||||
|
||||
String macHex1 = mac.digestHex(testStr);
|
||||
Assert.assertEquals("58a0d231315664af51b858a174eabc21", macHex1);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user