Support HMAC algorithm functions #470

This commit is contained in:
Francis Dong
2023-03-16 14:31:47 +08:00
committed by linwaiwai
parent 4629b24101
commit b6b3bc474a
2 changed files with 7 additions and 7 deletions

View File

@@ -189,27 +189,27 @@ public class CodecFunc implements IFunc {
} }
} }
public String hmacMd5(String secretKey, String data) { public String hmacMd5(String data, String secretKey) {
return new HmacUtils(HmacAlgorithms.HMAC_MD5, secretKey).hmacHex(data); return new HmacUtils(HmacAlgorithms.HMAC_MD5, secretKey).hmacHex(data);
} }
public String hmacSha1(String secretKey, String data) { public String hmacSha1(String data, String secretKey) {
return new HmacUtils(HmacAlgorithms.HMAC_SHA_1, secretKey).hmacHex(data); return new HmacUtils(HmacAlgorithms.HMAC_SHA_1, secretKey).hmacHex(data);
} }
public String hmacSha224(String secretKey, String data) { public String hmacSha224(String data, String secretKey) {
return new HmacUtils(HmacAlgorithms.HMAC_SHA_224, secretKey).hmacHex(data); return new HmacUtils(HmacAlgorithms.HMAC_SHA_224, secretKey).hmacHex(data);
} }
public String hmacSha256(String secretKey, String data) { public String hmacSha256(String data, String secretKey) {
return new HmacUtils(HmacAlgorithms.HMAC_SHA_256, secretKey).hmacHex(data); return new HmacUtils(HmacAlgorithms.HMAC_SHA_256, secretKey).hmacHex(data);
} }
public String hmacSha384(String secretKey, String data) { public String hmacSha384(String data, String secretKey) {
return new HmacUtils(HmacAlgorithms.HMAC_SHA_384, secretKey).hmacHex(data); return new HmacUtils(HmacAlgorithms.HMAC_SHA_384, secretKey).hmacHex(data);
} }
public String hmacSha512(String secretKey, String data) { public String hmacSha512(String data, String secretKey) {
return new HmacUtils(HmacAlgorithms.HMAC_SHA_512, secretKey).hmacHex(data); return new HmacUtils(HmacAlgorithms.HMAC_SHA_512, secretKey).hmacHex(data);
} }

View File

@@ -125,7 +125,7 @@ class CodecFuncTests {
@Test @Test
void testHmacSha256() { void testHmacSha256() {
String funcExpression = "fn.codec.hmacSha256(\"635e8562b968bc05bb80cacf124ebd53285280ee6845df0000faa33acafc38f0\", \"12345678123456781234567812345678\")"; String funcExpression = "fn.codec.hmacSha256(\"12345678123456781234567812345678\", \"635e8562b968bc05bb80cacf124ebd53285280ee6845df0000faa33acafc38f0\")";
Object result = FuncExecutor.getInstance().exec(null, funcExpression); Object result = FuncExecutor.getInstance().exec(null, funcExpression);
assertEquals("c61be0237ec186df1c5f51425e607093b260a76e5de43a62cb3e821103303990", result.toString()); assertEquals("c61be0237ec186df1c5f51425e607093b260a76e5de43a62cb3e821103303990", result.toString());
} }