From 07b049cb72b59d9d05531020e6ba49ebdd63202e Mon Sep 17 00:00:00 2001 From: sgrampone Date: Tue, 21 Jan 2025 18:38:41 +0000 Subject: [PATCH] Cherry pick branch 'genexuslabs:gamutils_eo' into beta --- .../main/java/com/genexus/gam/GamUtilsEO.java | 20 +++--- .../java/com/genexus/gam/utils/Encoding.java | 27 +++++++ .../genexus/gam/utils/json/JWTAlgorithm.java | 72 +++++++++++++++++++ .../java/com/genexus/gam/utils/json/Jwt.java | 51 ++++++------- .../genexus/gam/utils/test/EncodingTest.java | 12 +++- .../com/genexus/gam/utils/test/JwtTest.java | 58 +++++++-------- 6 files changed, 170 insertions(+), 70 deletions(-) create mode 100644 gamutils/src/main/java/com/genexus/gam/utils/json/JWTAlgorithm.java diff --git a/gamutils/src/main/java/com/genexus/gam/GamUtilsEO.java b/gamutils/src/main/java/com/genexus/gam/GamUtilsEO.java index 285e824e8..ee03fdbc8 100644 --- a/gamutils/src/main/java/com/genexus/gam/GamUtilsEO.java +++ b/gamutils/src/main/java/com/genexus/gam/GamUtilsEO.java @@ -57,16 +57,12 @@ public static String getJwkAlgorithm(String jwkString) { } //**JWT**// - public static boolean verifyJwtRsa(String path, String alias, String password, String token) { - return Jwt.verify(path, alias, password, token, "", false); + public static boolean verifyJwt(String path, String alias, String password, String token) { + return Jwt.verify(path, alias, password, token); } - public static String createJwtRsa(String path, String alias, String password, String payload, String header) { - return Jwt.create(path, alias, password, payload, header, "", false); - } - - public static boolean verifyJwtSha(String secret, String token) { - return Jwt.verify("", "", "", token, secret, true); + public static String createJwt(String path, String alias, String password, String payload, String header) { + return Jwt.create(path, alias, password, payload, header); } public static boolean verifyAlgorithm(String expectedAlgorithm, String token) @@ -74,10 +70,6 @@ public static boolean verifyAlgorithm(String expectedAlgorithm, String token) return Jwt.verifyAlgorithm(expectedAlgorithm, token); } - public static String createJwtSha(String secret, String payload, String header) { - return Jwt.create("", "", "", payload, header, secret, true); - } - public static long createUnixTimestamp(Date date) { return UnixTimestamp.create(date); } @@ -97,5 +89,9 @@ public static String base64ToBase64Url(String base64) { public static String hexaToBase64(String hexa) { return Encoding.hexaToBase64(hexa); } + public static String toBase64Url(String input) { return Encoding.toBase64Url(input); } + + public static String fromBase64Url(String base64) { return Encoding.fromBase64Url(base64); } + /********EXTERNAL OBJECT PUBLIC METHODS - END ********/ } diff --git a/gamutils/src/main/java/com/genexus/gam/utils/Encoding.java b/gamutils/src/main/java/com/genexus/gam/utils/Encoding.java index 73b824c89..8d92fd0be 100644 --- a/gamutils/src/main/java/com/genexus/gam/utils/Encoding.java +++ b/gamutils/src/main/java/com/genexus/gam/utils/Encoding.java @@ -1,12 +1,15 @@ package com.genexus.gam.utils; +import com.nimbusds.jose.util.Base64URL; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.bouncycastle.util.encoders.Base64; import org.bouncycastle.util.encoders.Hex; import org.bouncycastle.util.encoders.UrlBase64; +import java.nio.charset.StandardCharsets; + public class Encoding { private static final Logger logger = LogManager.getLogger(Encoding.class); @@ -32,4 +35,28 @@ public static String hexaToBase64(String hexa) return ""; } } + + public static String toBase64Url(String input) + { + logger.debug("UTF8toBase64Url"); + try{ + return new String(UrlBase64.encode(input.getBytes(StandardCharsets.UTF_8))); + }catch (Exception e) + { + logger.error("UTF8toBase64Url", e); + return ""; + } + } + + public static String fromBase64Url(String base64Url) + { + logger.debug("fromBase64Url"); + try{ + return new String(UrlBase64.decode(base64Url), StandardCharsets.UTF_8); + }catch (Exception e) + { + logger.error("fromBase64Url", e); + return ""; + } + } } diff --git a/gamutils/src/main/java/com/genexus/gam/utils/json/JWTAlgorithm.java b/gamutils/src/main/java/com/genexus/gam/utils/json/JWTAlgorithm.java new file mode 100644 index 000000000..56ae300ab --- /dev/null +++ b/gamutils/src/main/java/com/genexus/gam/utils/json/JWTAlgorithm.java @@ -0,0 +1,72 @@ +package com.genexus.gam.utils.json; + +import com.nimbusds.jose.JWSAlgorithm; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public enum JWTAlgorithm { + + HS256, HS512, HS384, RS256, RS512; + + private static final Logger logger = LogManager.getLogger(JWTAlgorithm.class); + + public static JWSAlgorithm getJWSAlgorithm(JWTAlgorithm alg) + { + logger.debug("getJWSAlgorithm"); + switch (alg) + { + case HS256: + return JWSAlgorithm.HS256; + case HS512: + return JWSAlgorithm.HS512; + case HS384: + return JWSAlgorithm.HS384; + case RS256: + return JWSAlgorithm.RS256; + case RS512: + return JWSAlgorithm.RS512; + default: + logger.error("getJWSAlgorithm - not implemented algorithm"); + return null; + } + } + + public static JWTAlgorithm getJWTAlgoritm(String alg) + { + logger.debug("getJWTAlgoritm"); + switch (alg.trim().toUpperCase()) + { + case "HS256": + return JWTAlgorithm.HS256; + case "HS512": + return JWTAlgorithm.HS512; + case "HS384": + return JWTAlgorithm.HS384; + case "RS256": + return JWTAlgorithm.RS256; + case "RS512": + return JWTAlgorithm.RS512; + default: + logger.error("getJWTAlgoritm- not implemented algorithm"); + return null; + } + } + + public static boolean isSymmetric(JWTAlgorithm alg) + { + logger.debug("isSymmetric"); + switch (alg) + { + case HS256: + case HS384: + case HS512: + return true; + case RS256: + case RS512: + return false; + default: + logger.error("isSymmetric - not implemented algorithm"); + return false; + } + } +} diff --git a/gamutils/src/main/java/com/genexus/gam/utils/json/Jwt.java b/gamutils/src/main/java/com/genexus/gam/utils/json/Jwt.java index 45f34f7a3..64709fe5b 100644 --- a/gamutils/src/main/java/com/genexus/gam/utils/json/Jwt.java +++ b/gamutils/src/main/java/com/genexus/gam/utils/json/Jwt.java @@ -2,10 +2,7 @@ import com.genexus.gam.utils.keys.PrivateKeyUtil; import com.genexus.gam.utils.keys.PublicKeyUtil; -import com.nimbusds.jose.JWSAlgorithm; -import com.nimbusds.jose.JWSHeader; -import com.nimbusds.jose.JWSSigner; -import com.nimbusds.jose.JWSVerifier; +import com.nimbusds.jose.*; import com.nimbusds.jose.crypto.MACSigner; import com.nimbusds.jose.crypto.MACVerifier; import com.nimbusds.jose.crypto.RSASSASigner; @@ -17,6 +14,8 @@ import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; +import java.text.ParseException; +import java.util.Objects; public class Jwt { @@ -24,20 +23,20 @@ public class Jwt { /******** EXTERNAL OBJECT PUBLIC METHODS - BEGIN ********/ - public static boolean verify(String path, String alias, String password, String token, String secret, boolean isSymmetric) { + public static boolean verify(String path, String alias, String password, String token) { logger.debug("verify"); try { - return !isSymmetric ? verify_internal(PublicKeyUtil.getPublicKey(path, alias, password, token), token, "", isSymmetric) : verify_internal(null, token, secret, isSymmetric); + return verify_internal(path, alias, password, token); } catch (Exception e) { logger.error("verify", e); return false; } } - public static String create(String path, String alias, String password, String payload, String header, String secret, boolean isSymmetric) { + public static String create(String path, String alias, String password, String payload, String header) { logger.debug("create"); try { - return !isSymmetric ? create_internal(PrivateKeyUtil.getPrivateKey(path, alias, password), payload, header, "", isSymmetric): create_internal(null, payload, header, secret, isSymmetric); + return create_internal(path, alias, password, payload, header); }catch (Exception e) { logger.error("create", e); @@ -79,29 +78,25 @@ public static boolean verifyAlgorithm(String algorithm, String token) /******** EXTERNAL OBJECT PUBLIC METHODS - END ********/ - private static boolean verify_internal(RSAPublicKey publicKey, String token, String secret, boolean isSymmetric){ + private static boolean verify_internal(String path, String alias, String password, String token) throws JOSEException, ParseException { logger.debug("verify_internal"); - try { - SignedJWT signedJWT = SignedJWT.parse(token); - JWSVerifier verifier = isSymmetric ? new MACVerifier(secret):new RSASSAVerifier(publicKey); - return signedJWT.verify(verifier); - } catch (Exception e) { - logger.error("verify_internal", e); - return false; - } + JWTAlgorithm algorithm = JWTAlgorithm.getJWTAlgoritm(JWSHeader.parse(getHeader(token)).getAlgorithm().getName()); + assert algorithm != null; + boolean isSymmetric = JWTAlgorithm.isSymmetric(algorithm); + SignedJWT signedJWT = SignedJWT.parse(token); + JWSVerifier verifier = isSymmetric ? new MACVerifier(password):new RSASSAVerifier(Objects.requireNonNull(PublicKeyUtil.getPublicKey(path, alias, password, token))); + return signedJWT.verify(verifier); } - private static String create_internal(RSAPrivateKey privateKey, String payload, String header, String secret, boolean isSymmetric) { + private static String create_internal(String path, String alias, String password, String payload, String header) throws Exception { logger.debug("create_internal"); - try { - SignedJWT signedJWT = new SignedJWT(JWSHeader.parse(header), JWTClaimsSet.parse(payload)); - JWSSigner signer = isSymmetric ? new MACSigner(secret): new RSASSASigner(privateKey); - signedJWT.sign(signer); - return signedJWT.serialize(); - } catch (Exception e) { - logger.error("create_internal", e); - return ""; - } + JWSHeader parsedHeader = JWSHeader.parse(header); + JWTAlgorithm algorithm = JWTAlgorithm.getJWTAlgoritm(parsedHeader.getAlgorithm().getName()); + assert algorithm != null; + boolean isSymmetric = JWTAlgorithm.isSymmetric(algorithm); + SignedJWT signedJWT = new SignedJWT(parsedHeader, JWTClaimsSet.parse(payload)); + JWSSigner signer = isSymmetric ? new MACSigner(password): new RSASSASigner(Objects.requireNonNull(PrivateKeyUtil.getPrivateKey(path, alias, password))); + signedJWT.sign(signer); + return signedJWT.serialize(); } - } diff --git a/gamutils/src/test/java/com/genexus/gam/utils/test/EncodingTest.java b/gamutils/src/test/java/com/genexus/gam/utils/test/EncodingTest.java index 7771a54f4..fa8ebd66f 100644 --- a/gamutils/src/test/java/com/genexus/gam/utils/test/EncodingTest.java +++ b/gamutils/src/test/java/com/genexus/gam/utils/test/EncodingTest.java @@ -34,6 +34,17 @@ private static String b64UrlToUtf8(String base64Url) { } } + @Test + public void testToBase64Url() { + int i = 0; + do { + String randomString = GamUtilsEO.randomAlphanumeric(128); + String testing = GamUtilsEO.toBase64Url(randomString); + Assert.assertEquals("testB64ToB64Url", randomString, GamUtilsEO.fromBase64Url(testing)); + i++; + } while (i < 50); + } + @Test public void testHexaToBase64() { @@ -57,5 +68,4 @@ private static String b64ToHexa(String base64) { } - } diff --git a/gamutils/src/test/java/com/genexus/gam/utils/test/JwtTest.java b/gamutils/src/test/java/com/genexus/gam/utils/test/JwtTest.java index b17279773..45025a4ae 100644 --- a/gamutils/src/test/java/com/genexus/gam/utils/test/JwtTest.java +++ b/gamutils/src/test/java/com/genexus/gam/utils/test/JwtTest.java @@ -38,15 +38,15 @@ public static void setUp() { @Test public void test_pkcs8_pem() { - String token = GamUtilsEO.createJwtRsa(path_RSA_sha256_2048 + "sha256d_key.pem", "", "", payload, headerRsa); + String token = GamUtilsEO.createJwt(path_RSA_sha256_2048 + "sha256d_key.pem", "", "", payload, headerRsa); Assert.assertFalse("test_pkcs8 create", token.isEmpty()); - boolean result = GamUtilsEO.verifyJwtRsa(path_RSA_sha256_2048 + "sha256_cert.cer", "", "", token); + boolean result = GamUtilsEO.verifyJwt(path_RSA_sha256_2048 + "sha256_cert.cer", "", "", token); Assert.assertTrue("test_pkcs8 verify cer", result); } @Test public void test_get() { - String token = GamUtilsEO.createJwtRsa(path_RSA_sha256_2048 + "sha256d_key.pem", "", "", payload, headerRsa); + String token = GamUtilsEO.createJwt(path_RSA_sha256_2048 + "sha256d_key.pem", "", "", payload, headerRsa); Assert.assertFalse("test_get create", token.isEmpty()); String header_get = GamUtilsEO.getJwtHeader(token); Assert.assertFalse("test_get getHeader", header_get.isEmpty()); @@ -56,57 +56,57 @@ public void test_get() { @Test public void test_pkcs8_key() { - String token = GamUtilsEO.createJwtRsa(path_RSA_sha256_2048 + "sha256d_key.key", "", "", payload, headerRsa); + String token = GamUtilsEO.createJwt(path_RSA_sha256_2048 + "sha256d_key.key", "", "", payload, headerRsa); Assert.assertFalse("test_pkcs8 create", token.isEmpty()); - boolean result = GamUtilsEO.verifyJwtRsa(path_RSA_sha256_2048 + "sha256_cert.crt", "", "", token); + boolean result = GamUtilsEO.verifyJwt(path_RSA_sha256_2048 + "sha256_cert.crt", "", "", token); Assert.assertTrue("test_pkcs8 verify crt", result); } @Test public void test_pkcs8_encrypted() { - String token = GamUtilsEO.createJwtRsa(path_RSA_sha256_2048 + "sha256_key.pem", "", password, payload, headerRsa); + String token = GamUtilsEO.createJwt(path_RSA_sha256_2048 + "sha256_key.pem", "", password, payload, headerRsa); Assert.assertFalse("test_pkcs8_encrypted", token.isEmpty()); - boolean result = GamUtilsEO.verifyJwtRsa(path_RSA_sha256_2048 + "sha256_cert.crt", "", "", token); + boolean result = GamUtilsEO.verifyJwt(path_RSA_sha256_2048 + "sha256_cert.crt", "", "", token); Assert.assertTrue("test_pkcs8_encrypted verify crt", result); } @Test public void test_pkcs12_p12() { - String token = GamUtilsEO.createJwtRsa(path_RSA_sha256_2048 + "sha256_cert.p12", alias, password, payload, headerRsa); + String token = GamUtilsEO.createJwt(path_RSA_sha256_2048 + "sha256_cert.p12", alias, password, payload, headerRsa); Assert.assertFalse("test_pkcs12_p12 create", token.isEmpty()); - boolean result = GamUtilsEO.verifyJwtRsa(path_RSA_sha256_2048 + "sha256_cert.p12", alias, password, token); + boolean result = GamUtilsEO.verifyJwt(path_RSA_sha256_2048 + "sha256_cert.p12", alias, password, token); Assert.assertTrue("test_pkcs12_p12 verify", result); } @Test public void test_pkcs12_pkcs12() { - String token = GamUtilsEO.createJwtRsa(path_RSA_sha256_2048 + "sha256_cert.pkcs12", alias, password, payload, headerRsa); + String token = GamUtilsEO.createJwt(path_RSA_sha256_2048 + "sha256_cert.pkcs12", alias, password, payload, headerRsa); Assert.assertFalse("test_pkcs12_pkcs12 create", token.isEmpty()); - boolean result = GamUtilsEO.verifyJwtRsa(path_RSA_sha256_2048 + "sha256_cert.pkcs12", alias, password, token); + boolean result = GamUtilsEO.verifyJwt(path_RSA_sha256_2048 + "sha256_cert.pkcs12", alias, password, token); Assert.assertTrue("test_pkcs12_pkcs12 verify", result); } @Test public void test_pkcs12_jks() { - String token = GamUtilsEO.createJwtRsa(path_RSA_sha256_2048 + "sha256_cert.jks", alias, password, payload, headerRsa); + String token = GamUtilsEO.createJwt(path_RSA_sha256_2048 + "sha256_cert.jks", alias, password, payload, headerRsa); Assert.assertFalse("test_pkcs12_jks create", token.isEmpty()); - boolean result = GamUtilsEO.verifyJwtRsa(path_RSA_sha256_2048 + "sha256_cert.jks", alias, password, token); + boolean result = GamUtilsEO.verifyJwt(path_RSA_sha256_2048 + "sha256_cert.jks", alias, password, token); Assert.assertTrue("test_pkcs12_jks verify", result); } @Test public void test_pkcs12_pfx() { - String token = GamUtilsEO.createJwtRsa(path_RSA_sha256_2048 + "sha256_cert.pfx", alias, password, payload, headerRsa); + String token = GamUtilsEO.createJwt(path_RSA_sha256_2048 + "sha256_cert.pfx", alias, password, payload, headerRsa); Assert.assertFalse("test_pkcs12_pfx create", token.isEmpty()); - boolean result = GamUtilsEO.verifyJwtRsa(path_RSA_sha256_2048 + "sha256_cert.pfx", alias, password, token); + boolean result = GamUtilsEO.verifyJwt(path_RSA_sha256_2048 + "sha256_cert.pfx", alias, password, token); Assert.assertTrue("test_pkcs12_pfx verify", result); } @Test public void test_pkcs12_noalias() { - String token = GamUtilsEO.createJwtRsa(path_RSA_sha256_2048 + "sha256_cert.jks", "", password, payload, headerRsa); + String token = GamUtilsEO.createJwt(path_RSA_sha256_2048 + "sha256_cert.jks", "", password, payload, headerRsa); Assert.assertFalse("test_pkcs12_noalias jks create", token.isEmpty()); - boolean result = GamUtilsEO.verifyJwtRsa(path_RSA_sha256_2048 + "sha256_cert.jks", "", password, token); + boolean result = GamUtilsEO.verifyJwt(path_RSA_sha256_2048 + "sha256_cert.jks", "", password, token); Assert.assertTrue("test_pkcs12_noalias jks verify", result); } @@ -114,19 +114,19 @@ public void test_pkcs12_noalias() { public void test_b64() { String publicKey = "MIIEATCCAumgAwIBAgIJAIAqvKHZ+gFhMA0GCSqGSIb3DQEBCwUAMIGWMQswCQYDVQQGEwJVWTETMBEGA1UECAwKTW9udGV2aWRlbzETMBEGA1UEBwwKTW9udGV2aWRlbzEQMA4GA1UECgwHR2VuZVh1czERMA8GA1UECwwIU2VjdXJpdHkxEjAQBgNVBAMMCXNncmFtcG9uZTEkMCIGCSqGSIb3DQEJARYVc2dyYW1wb25lQGdlbmV4dXMuY29tMB4XDTIwMDcwODE4NTcxN1oX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GPvo36WjuXAKWWjcRodzRgo57z9achCyMKhGU5yDOxh8jhkCgYAx6rtwoSlDcwQzAjfEe4Wo+PAL5gcLLPrGvjMiAYwJ08Pc/ectl9kP9j2J2qj4kSclTw9KApyGZuOfUagn2Zxhqkd7yhTzHJp4tM7uay1DrueYR1NyYYkisXfD87J1z8forsDwNLVtglzTy6p56674sgGa7bifZBmv+4OJco286QKBgQC4dGXDHGDNg36G590A1zpw8ILxyM7YPEPOOfxy3rGeypEqV6AZy13KLlq84DFM+xwvrBYvsW1hJIbcsFpjuMRZ8MGjDu0Us6JTkOO4bc32vgKzlBB9O85XdeSf6J1zrenwVOaWut5BbMiwjfOTpMdrzg71QV/XI0w7NGoApJp1cQKBgERfI6AfJTaKtEpfX3udR1B3zra1Y42ppU2TvGI5J2/cItENoyRmtyKYDp2I036/Pe63nuIzs31i6q/hCr9Tv3AGoSVKuPLpCWv5xVO/BPhGs5dwx81nUo0/P+H2X8dx7g57PQY4uf4F9+EIXeAdbPqfB8GBW7RX3FDx5NpB+Hh/"; - String token = GamUtilsEO.createJwtRsa(privateKey, "", "", payload, headerRsa); + String token = GamUtilsEO.createJwt(privateKey, "", "", payload, headerRsa); Assert.assertFalse("test_b64 create", token.isEmpty()); - boolean result = GamUtilsEO.verifyJwtRsa(publicKey, "", "", token); + boolean result = GamUtilsEO.verifyJwt(publicKey, "", "", token); Assert.assertTrue("test_b64 verify", result); } @Test public void test_json_jwk() { String keyPair = GamUtilsEO.generateKeyPair(); - String token = GamUtilsEO.createJwtRsa(keyPair, "", "", payload, headerRsa); + String token = GamUtilsEO.createJwt(keyPair, "", "", payload, headerRsa); Assert.assertFalse("test_json_jwk create", token.isEmpty()); String publicJwk = GamUtilsEO.getPublicJwk(keyPair); - boolean result = GamUtilsEO.verifyJwtRsa(publicJwk, "", "", token); + boolean result = GamUtilsEO.verifyJwt(publicJwk, "", "", token); Assert.assertTrue("test_json_jwk verify", result); } @@ -135,10 +135,10 @@ public void test_json_jwks() { String keyPair = GamUtilsEO.generateKeyPair(); String publicJwk = GamUtilsEO.getPublicJwk(keyPair); String header_jwks = makeHeader(publicJwk); - String token = GamUtilsEO.createJwtRsa(keyPair, "", "", payload, header_jwks); + String token = GamUtilsEO.createJwt(keyPair, "", "", payload, header_jwks); Assert.assertFalse("test_json_jwks create", token.isEmpty()); String publicJwks = "{\"keys\": [" + publicJwk + "]}"; - boolean result = GamUtilsEO.verifyJwtRsa(publicJwks, "", "", token); + boolean result = GamUtilsEO.verifyJwt(publicJwks, "", "", token); Assert.assertTrue("test_json_jwks verify", result); } @@ -152,9 +152,9 @@ public void test_json_Sha256() int[] lengths = new int[]{32, 64, 128}; for (int n : lengths) { String secret = GamUtilsEO.randomAlphanumeric(n); - String token = GamUtilsEO.createJwtSha(secret, payload, header); + String token = GamUtilsEO.createJwt("", "", secret, payload, header); Assert.assertFalse("test_json_Sha256 create", token.isEmpty()); - boolean result = GamUtilsEO.verifyJwtSha(secret, token); + boolean result = GamUtilsEO.verifyJwt("", "", secret, token); Assert.assertTrue("test_json_Sha256 verify", result); } } @@ -169,9 +169,9 @@ public void test_json_Sha512() int[] lengths = new int[]{64, 128}; for (int n : lengths) { String secret = GamUtilsEO.randomAlphanumeric(n); - String token = GamUtilsEO.createJwtSha(secret, payload, header); + String token = GamUtilsEO.createJwt("", "", secret, payload, header); Assert.assertFalse("test_json_Sha512 create", token.isEmpty()); - boolean result = GamUtilsEO.verifyJwtSha(secret, token); + boolean result = GamUtilsEO.verifyJwt("", "", secret, token); Assert.assertTrue("test_json_Sha512 verify", result); } } @@ -184,7 +184,7 @@ public void test_VerifyAlgorithm_True() " \"typ\": \"JWT\"\n" + "}"; String secret = GamUtilsEO.randomAlphanumeric(64); - String token = GamUtilsEO.createJwtSha(secret, payload, header); + String token = GamUtilsEO.createJwt("", "", secret, payload, header); boolean resultSha512 = GamUtilsEO.verifyAlgorithm("HS512", token); Assert.assertTrue("test_VerifyAlgorithm_True", resultSha512); } @@ -197,7 +197,7 @@ public void test_VerifyAlgorithm_False() " \"typ\": \"JWT\"\n" + "}"; String secret = GamUtilsEO.randomAlphanumeric(64); - String token = GamUtilsEO.createJwtSha(secret, payload, header); + String token = GamUtilsEO.createJwt("", "", secret, payload, header); boolean resultSha512 = GamUtilsEO.verifyAlgorithm("RS256", token); Assert.assertFalse("test_VerifyAlgorithm_False", resultSha512); }