com.auth0.jwt.interfaces.RSAKeyProvider Java Examples

The following examples show how to use com.auth0.jwt.interfaces.RSAKeyProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RS256SignatureVerifier.java    From auth0-java with MIT License 6 votes vote down vote up
private static Algorithm getAlgorithm(final PublicKeyProvider publicKeyProvider) {
    return Algorithm.RSA256(new RSAKeyProvider() {
        @Override
        public RSAPublicKey getPublicKeyById(String keyId) {
            try {
                return publicKeyProvider.getPublicKeyById(keyId);
            } catch (PublicKeyProviderException pke) {
                throw new IdTokenValidationException(String.format("Could not find a public key for Key ID (kid) \"%s\"", keyId), pke);
            }
        }

        @Override
        public RSAPrivateKey getPrivateKey() {
            // no-op
            return null;
        }

        @Override
        public String getPrivateKeyId() {
            // no-op
            return null;
        }
    });
}
 
Example #2
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 6 votes vote down vote up
@Test
public void shouldThrowOnSignWhenTheSignatureIsNotPrepared() throws Exception {
    exception.expect(SignatureGenerationException.class);
    exception.expectMessage("The Token's Signature couldn't be generated when signing using the Algorithm: some-algorithm");
    exception.expectCause(isA(SignatureException.class));

    CryptoHelper crypto = mock(CryptoHelper.class);
    when(crypto.createSignatureFor(anyString(), any(PrivateKey.class), any(byte[].class), any(byte[].class)))
            .thenThrow(SignatureException.class);

    RSAPublicKey publicKey = mock(RSAPublicKey.class);
    RSAPrivateKey privateKey = mock(RSAPrivateKey.class);
    RSAKeyProvider provider = RSAAlgorithm.providerForKeys(publicKey, privateKey);
    Algorithm algorithm = new RSAAlgorithm(crypto, "some-alg", "some-algorithm", provider);
    algorithm.sign(new byte[0], new byte[0]);
}
 
Example #3
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 6 votes vote down vote up
@Test
public void shouldThrowOnSignWhenThePrivateKeyIsInvalid() throws Exception {
    exception.expect(SignatureGenerationException.class);
    exception.expectMessage("The Token's Signature couldn't be generated when signing using the Algorithm: some-algorithm");
    exception.expectCause(isA(InvalidKeyException.class));

    CryptoHelper crypto = mock(CryptoHelper.class);
    when(crypto.createSignatureFor(anyString(), any(PrivateKey.class), any(byte[].class), any(byte[].class)))
            .thenThrow(InvalidKeyException.class);

    RSAPublicKey publicKey = mock(RSAPublicKey.class);
    RSAPrivateKey privateKey = mock(RSAPrivateKey.class);
    RSAKeyProvider provider = RSAAlgorithm.providerForKeys(publicKey, privateKey);
    Algorithm algorithm = new RSAAlgorithm(crypto, "some-alg", "some-algorithm", provider);
    algorithm.sign(new byte[0], new byte[0]);
}
 
Example #4
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 6 votes vote down vote up
@Test
public void shouldThrowOnSignWhenSignatureAlgorithmDoesNotExists() throws Exception {
    exception.expect(SignatureGenerationException.class);
    exception.expectMessage("The Token's Signature couldn't be generated when signing using the Algorithm: some-algorithm");
    exception.expectCause(isA(NoSuchAlgorithmException.class));

    CryptoHelper crypto = mock(CryptoHelper.class);
    when(crypto.createSignatureFor(anyString(), any(PrivateKey.class), any(byte[].class), any(byte[].class)))
            .thenThrow(NoSuchAlgorithmException.class);

    RSAPublicKey publicKey = mock(RSAPublicKey.class);
    RSAPrivateKey privateKey = mock(RSAPrivateKey.class);
    RSAKeyProvider provider = RSAAlgorithm.providerForKeys(publicKey, privateKey);
    Algorithm algorithm = new RSAAlgorithm(crypto, "some-alg", "some-algorithm", provider);
    algorithm.sign(new byte[0], new byte[0]);
}
 
Example #5
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 6 votes vote down vote up
@Test
public void shouldThrowWhenTheSignatureIsNotPrepared() throws Exception {
    exception.expect(SignatureVerificationException.class);
    exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: some-alg");
    exception.expectCause(isA(SignatureException.class));

    CryptoHelper crypto = mock(CryptoHelper.class);
    when(crypto.verifySignatureFor(anyString(), any(PublicKey.class), any(String.class), any(String.class), any(byte[].class)))
            .thenThrow(SignatureException.class);

    RSAPublicKey publicKey = mock(RSAPublicKey.class);
    RSAPrivateKey privateKey = mock(RSAPrivateKey.class);
    RSAKeyProvider provider = RSAAlgorithm.providerForKeys(publicKey, privateKey);
    Algorithm algorithm = new RSAAlgorithm(crypto, "some-alg", "some-algorithm", provider);
    String jwt = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.dxXF3MdsyW-AuvwJpaQtrZ33fAde9xWxpLIg9cO2tMLH2GSRNuLAe61KsJusZhqZB9Iy7DvflcmRz-9OZndm6cj_ThGeJH2LLc90K83UEvvRPo8l85RrQb8PcanxCgIs2RcZOLygERizB3pr5icGkzR7R2y6zgNCjKJ5_NJ6EiZsGN6_nc2PRK_DbyY-Wn0QDxIxKoA5YgQJ9qafe7IN980pXvQv2Z62c3XR8dYuaXBqhthBj-AbaFHEpZapN-V-TmuLNzR2MCB6Xr7BYMuCaqWf_XU8og4XNe8f_8w9Wv5vvgqMM1KhqVpG5VdMJv4o_L4NoCROHhtUQSLRh2M9cA";
    algorithm.verify(JWT.decode(jwt));
}
 
Example #6
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 6 votes vote down vote up
@Test
public void shouldThrowWhenMacAlgorithmDoesNotExists() throws Exception {
    exception.expect(SignatureVerificationException.class);
    exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: some-alg");
    exception.expectCause(isA(NoSuchAlgorithmException.class));
    
    CryptoHelper crypto = mock(CryptoHelper.class);
    when(crypto.verifySignatureFor(anyString(), any(PublicKey.class), any(String.class), any(String.class), any(byte[].class)))
            .thenThrow(NoSuchAlgorithmException.class);

    RSAPublicKey publicKey = mock(RSAPublicKey.class);
    RSAPrivateKey privateKey = mock(RSAPrivateKey.class);
    RSAKeyProvider provider = RSAAlgorithm.providerForKeys(publicKey, privateKey);
    Algorithm algorithm = new RSAAlgorithm(crypto, "some-alg", "some-algorithm", provider);
    String jwt = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.dxXF3MdsyW-AuvwJpaQtrZ33fAde9xWxpLIg9cO2tMLH2GSRNuLAe61KsJusZhqZB9Iy7DvflcmRz-9OZndm6cj_ThGeJH2LLc90K83UEvvRPo8l85RrQb8PcanxCgIs2RcZOLygERizB3pr5icGkzR7R2y6zgNCjKJ5_NJ6EiZsGN6_nc2PRK_DbyY-Wn0QDxIxKoA5YgQJ9qafe7IN980pXvQv2Z62c3XR8dYuaXBqhthBj-AbaFHEpZapN-V-TmuLNzR2MCB6Xr7BYMuCaqWf_XU8og4XNe8f_8w9Wv5vvgqMM1KhqVpG5VdMJv4o_L4NoCROHhtUQSLRh2M9cA";
    algorithm.verify(JWT.decode(jwt));
}
 
Example #7
Source File: JWTCreatorTest.java    From java-jwt with MIT License 6 votes vote down vote up
@Test
public void shouldNotOverwriteKeyIdIfAddedFromRSAAlgorithms() throws Exception {
    RSAPrivateKey privateKey = (RSAPrivateKey) PemUtils.readPrivateKeyFromFile(PRIVATE_KEY_FILE_RSA, "RSA");
    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    when(provider.getPrivateKeyId()).thenReturn("my-key-id");
    when(provider.getPrivateKey()).thenReturn(privateKey);

    String signed = JWTCreator.init()
            .withKeyId("real-key-id")
            .sign(Algorithm.RSA256(provider));

    assertThat(signed, is(notNullValue()));
    String[] parts = signed.split("\\.");
    String headerJson = new String(Base64.decodeBase64(parts[0]), StandardCharsets.UTF_8);
    assertThat(headerJson, JsonMatcher.hasEntry("kid", "my-key-id"));
}
 
Example #8
Source File: RSAAlgorithm.java    From java-jwt with MIT License 6 votes vote down vote up
static RSAKeyProvider providerForKeys(final RSAPublicKey publicKey, final RSAPrivateKey privateKey) {
    if (publicKey == null && privateKey == null) {
        throw new IllegalArgumentException("Both provided Keys cannot be null.");
    }
    return new RSAKeyProvider() {
        @Override
        public RSAPublicKey getPublicKeyById(String keyId) {
            return publicKey;
        }

        @Override
        public RSAPrivateKey getPrivateKey() {
            return privateKey;
        }

        @Override
        public String getPrivateKeyId() {
            return null;
        }
    };
}
 
Example #9
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldDoRSA384SigningWithProvidedPrivateKey() throws Exception {
    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    PrivateKey privateKey = readPrivateKeyFromFile(PRIVATE_KEY_FILE, "RSA");
    PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE, "RSA");
    when(provider.getPrivateKey()).thenReturn((RSAPrivateKey) privateKey);
    when(provider.getPublicKeyById(null)).thenReturn((RSAPublicKey) publicKey);
    Algorithm algorithm = Algorithm.RSA384(provider);
    
    String jwt = asJWT(algorithm, RS384Header, auth0IssPayload);

    assertSignaturePresent(jwt);
    algorithm.verify(JWT.decode(jwt));
}
 
Example #10
Source File: AlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldCreateRSA512AlgorithmWithProvider() throws Exception {
    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    Algorithm algorithm = Algorithm.RSA512(provider);

    assertThat(algorithm, is(notNullValue()));
    assertThat(algorithm, is(instanceOf(RSAAlgorithm.class)));
    assertThat(algorithm.getDescription(), is("SHA512withRSA"));
    assertThat(algorithm.getName(), is("RS512"));
}
 
Example #11
Source File: AlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldCreateRSA384AlgorithmWithProvider() throws Exception {
    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    Algorithm algorithm = Algorithm.RSA384(provider);

    assertThat(algorithm, is(notNullValue()));
    assertThat(algorithm, is(instanceOf(RSAAlgorithm.class)));
    assertThat(algorithm.getDescription(), is("SHA384withRSA"));
    assertThat(algorithm.getName(), is("RS384"));
}
 
Example #12
Source File: AlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldCreateRSA256AlgorithmWithProvider() throws Exception {
    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    Algorithm algorithm = Algorithm.RSA256(provider);

    assertThat(algorithm, is(notNullValue()));
    assertThat(algorithm, is(instanceOf(RSAAlgorithm.class)));
    assertThat(algorithm.getDescription(), is("SHA256withRSA"));
    assertThat(algorithm.getName(), is("RS256"));
}
 
Example #13
Source File: AlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldThrowRSA512InstanceWithNullKeyProvider() throws Exception {
    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("The Key Provider cannot be null.");
    RSAKeyProvider provider = null;
    Algorithm.RSA512(provider);
}
 
Example #14
Source File: AlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldThrowRSA384InstanceWithNullKeyProvider() throws Exception {
    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("The Key Provider cannot be null.");
    RSAKeyProvider provider = null;
    Algorithm.RSA384(provider);
}
 
Example #15
Source File: AlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldThrowRSA256InstanceWithNullKeyProvider() throws Exception {
    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("The Key Provider cannot be null.");
    RSAKeyProvider provider = null;
    Algorithm.RSA256(provider);
}
 
Example #16
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
/**
 * Test deprecated signing method error handling.
 * 
 * @see {@linkplain #shouldFailOnRSA256SigningWhenProvidedPrivateKeyIsNull}
 * @throws Exception expected exception
 */

@Test
public void shouldFailOnRSA256SigningWithDeprecatedMethodWhenProvidedPrivateKeyIsNull() throws Exception {
    exception.expect(SignatureGenerationException.class);
    exception.expectMessage("The Token's Signature couldn't be generated when signing using the Algorithm: SHA256withRSA");
    exception.expectCause(isA(IllegalStateException.class));
    exception.expectCause(hasMessage(is("The given Private Key is null.")));

    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    when(provider.getPrivateKey()).thenReturn(null);
    Algorithm algorithm = Algorithm.RSA256(provider);
    algorithm.sign(new byte[0]);
}
 
Example #17
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldReturnSigningKeyIdFromProvider() throws Exception {
    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    when(provider.getPrivateKeyId()).thenReturn("keyId");
    Algorithm algorithm = new RSAAlgorithm("some-alg", "some-algorithm", provider);

    assertThat(algorithm.getSigningKeyId(), is("keyId"));
}
 
Example #18
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldReturnNullSigningKeyIdIfCreatedWithDefaultProvider() throws Exception {
    RSAPublicKey publicKey = mock(RSAPublicKey.class);
    RSAPrivateKey privateKey = mock(RSAPrivateKey.class);
    RSAKeyProvider provider = RSAAlgorithm.providerForKeys(publicKey, privateKey);
    Algorithm algorithm = new RSAAlgorithm("some-alg", "some-algorithm", provider);

    assertThat(algorithm.getSigningKeyId(), is(nullValue()));
}
 
Example #19
Source File: AsymmetricSignatureVerifier.java    From auth0-java-mvc-common with MIT License 5 votes vote down vote up
private static JWTVerifier createJWTVerifier(final JwkProvider jwkProvider) {
    Algorithm alg = Algorithm.RSA256(new RSAKeyProvider() {
        @Override
        public RSAPublicKey getPublicKeyById(String keyId) {
            try {
                Jwk jwk = jwkProvider.get(keyId);
                return (RSAPublicKey) jwk.getPublicKey();
            } catch (JwkException ignored) {
                // JwkException handled by Algorithm verify implementation from java-jwt
            }
            return null;
        }

        @Override
        public RSAPrivateKey getPrivateKey() {
            //NO-OP
            return null;
        }

        @Override
        public String getPrivateKeyId() {
            //NO-OP
            return null;
        }
    });
    return JWT.require(alg)
            .ignoreIssuedAt()
            .build();
}
 
Example #20
Source File: RSAAlgorithm.java    From java-jwt with MIT License 5 votes vote down vote up
RSAAlgorithm(CryptoHelper crypto, String id, String algorithm, RSAKeyProvider keyProvider) throws IllegalArgumentException {
    super(id, algorithm);
    if (keyProvider == null) {
        throw new IllegalArgumentException("The Key Provider cannot be null.");
    }
    this.keyProvider = keyProvider;
    this.crypto = crypto;
}
 
Example #21
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldFailOnRSA512SigningWhenProvidedPrivateKeyIsNull() throws Exception {
    exception.expect(SignatureGenerationException.class);
    exception.expectMessage("The Token's Signature couldn't be generated when signing using the Algorithm: SHA512withRSA");
    exception.expectCause(isA(IllegalStateException.class));
    exception.expectCause(hasMessage(is("The given Private Key is null.")));

    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    when(provider.getPrivateKey()).thenReturn(null);
    Algorithm algorithm = Algorithm.RSA512(provider);
    algorithm.sign(new byte[0], new byte[0]);
}
 
Example #22
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldDoRSA512SigningWithProvidedPrivateKey() throws Exception {
    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    PrivateKey privateKey = readPrivateKeyFromFile(PRIVATE_KEY_FILE, "RSA");
    PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE, "RSA");
    when(provider.getPrivateKey()).thenReturn((RSAPrivateKey) privateKey);
    when(provider.getPublicKeyById(null)).thenReturn((RSAPublicKey) publicKey);
    Algorithm algorithm = Algorithm.RSA512(provider);
    
    String jwt = asJWT(algorithm, RS512Header, auth0IssPayload);

    assertSignaturePresent(jwt);
    algorithm.verify(JWT.decode(jwt));
}
 
Example #23
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldFailOnRSA384SigningWhenProvidedPrivateKeyIsNull() throws Exception {
    exception.expect(SignatureGenerationException.class);
    exception.expectMessage("The Token's Signature couldn't be generated when signing using the Algorithm: SHA384withRSA");
    exception.expectCause(isA(IllegalStateException.class));
    exception.expectCause(hasMessage(is("The given Private Key is null.")));

    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    when(provider.getPrivateKey()).thenReturn(null);
    Algorithm algorithm = Algorithm.RSA384(provider);
    algorithm.sign(new byte[0], new byte[0]);
}
 
Example #24
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldFailOnRSA256SigningWhenProvidedPrivateKeyIsNull() throws Exception {
    exception.expect(SignatureGenerationException.class);
    exception.expectMessage("The Token's Signature couldn't be generated when signing using the Algorithm: SHA256withRSA");
    exception.expectCause(isA(IllegalStateException.class));
    exception.expectCause(hasMessage(is("The given Private Key is null.")));

    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    when(provider.getPrivateKey()).thenReturn(null);
    Algorithm algorithm = Algorithm.RSA256(provider);
    algorithm.sign(new byte[0], new byte[0]);
}
 
Example #25
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldDoRSA256SigningWithProvidedPrivateKey() throws Exception {
    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    PrivateKey privateKey = readPrivateKeyFromFile(PRIVATE_KEY_FILE, "RSA");
    PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE, "RSA");
    when(provider.getPrivateKey()).thenReturn((RSAPrivateKey) privateKey);
    when(provider.getPublicKeyById(null)).thenReturn((RSAPublicKey) publicKey);
    Algorithm algorithm = Algorithm.RSA256(provider);
    
    String jwt = asJWT(algorithm, RS256Header, auth0IssPayload);

    assertSignaturePresent(jwt);
    algorithm.verify(JWT.decode(jwt));
}
 
Example #26
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldThrowWhenThePublicKeyIsInvalid() throws Exception {
    exception.expect(SignatureVerificationException.class);
    exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: some-alg");
    exception.expectCause(isA(InvalidKeyException.class));

    CryptoHelper crypto = mock(CryptoHelper.class);
    when(crypto.verifySignatureFor(anyString(), any(PublicKey.class), any(String.class), any(String.class), any(byte[].class)))
            .thenThrow(InvalidKeyException.class);

    RSAPublicKey publicKey = mock(RSAPublicKey.class);
    RSAPrivateKey privateKey = mock(RSAPrivateKey.class);
    RSAKeyProvider provider = RSAAlgorithm.providerForKeys(publicKey, privateKey);
    Algorithm algorithm = new RSAAlgorithm(crypto, "some-alg", "some-algorithm", provider);
    String jwt = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.dxXF3MdsyW-AuvwJpaQtrZ33fAde9xWxpLIg9cO2tMLH2GSRNuLAe61KsJusZhqZB9Iy7DvflcmRz-9OZndm6cj_ThGeJH2LLc90K83UEvvRPo8l85RrQb8PcanxCgIs2RcZOLygERizB3pr5icGkzR7R2y6zgNCjKJ5_NJ6EiZsGN6_nc2PRK_DbyY-Wn0QDxIxKoA5YgQJ9qafe7IN980pXvQv2Z62c3XR8dYuaXBqhthBj-AbaFHEpZapN-V-TmuLNzR2MCB6Xr7BYMuCaqWf_XU8og4XNe8f_8w9Wv5vvgqMM1KhqVpG5VdMJv4o_L4NoCROHhtUQSLRh2M9cA";
    algorithm.verify(JWT.decode(jwt));
}
 
Example #27
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldFailRSA512VerificationWhenProvidedPublicKeyIsNull() throws Exception {
    exception.expect(SignatureVerificationException.class);
    exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA512withRSA");
    exception.expectCause(isA(IllegalStateException.class));
    exception.expectCause(hasMessage(is("The given Public Key is null.")));
    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    when(provider.getPublicKeyById("my-key-id")).thenReturn(null);
    String jwt = "eyJhbGciOiJSUzUxMiIsImtpZCI6Im15LWtleS1pZCJ9.eyJpc3MiOiJhdXRoMCJ9.GpHv85Q8tAU_6hNWsmO0GEpO1qz9lmK3NKeAcemysz9MGo4FXWn8xbD8NjCfzZ8EWphm65M0NArKSjpKHO5-gcNsQxLBVfSED1vzcoaZH_Vy5Rp1M76dGH7JghB_66KrpfyMxer_yRJb-KXesNvIroDGilLQF2ENG-IfLF5nBKlDiVHmPaqr3pm1q20fNLhegkSRca4BJ5VdIlT6kOqE_ykVyCBqzD_oXp3LKO_ARnxoeB9SegIW1fy_3tuxSTKYsCZiOfiyVEXXblAuY3pSLZnGvgeBRnfvmWXDWhP0vVUFtYJBF09eULvvUMVqWcrjUG9gDzzzT7veiY_fHd_x8g";
    Algorithm algorithm = Algorithm.RSA512(provider);
    algorithm.verify(JWT.decode(jwt));
}
 
Example #28
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldPassRSA512VerificationWithProvidedPublicKey() throws Exception {
    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE, "RSA");
    when(provider.getPublicKeyById("my-key-id")).thenReturn((RSAPublicKey) publicKey);
    String jwt = "eyJhbGciOiJSUzUxMiIsImtpZCI6Im15LWtleS1pZCJ9.eyJpc3MiOiJhdXRoMCJ9.GpHv85Q8tAU_6hNWsmO0GEpO1qz9lmK3NKeAcemysz9MGo4FXWn8xbD8NjCfzZ8EWphm65M0NArKSjpKHO5-gcNsQxLBVfSED1vzcoaZH_Vy5Rp1M76dGH7JghB_66KrpfyMxer_yRJb-KXesNvIroDGilLQF2ENG-IfLF5nBKlDiVHmPaqr3pm1q20fNLhegkSRca4BJ5VdIlT6kOqE_ykVyCBqzD_oXp3LKO_ARnxoeB9SegIW1fy_3tuxSTKYsCZiOfiyVEXXblAuY3pSLZnGvgeBRnfvmWXDWhP0vVUFtYJBF09eULvvUMVqWcrjUG9gDzzzT7veiY_fHd_x8g";
    Algorithm algorithm = Algorithm.RSA512(provider);
    algorithm.verify(JWT.decode(jwt));
}
 
Example #29
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldFailRSA384VerificationWhenProvidedPublicKeyIsNull() throws Exception {
    exception.expect(SignatureVerificationException.class);
    exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA384withRSA");
    exception.expectCause(isA(IllegalStateException.class));
    exception.expectCause(hasMessage(is("The given Public Key is null.")));
    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    when(provider.getPublicKeyById("my-key-id")).thenReturn(null);
    String jwt = "eyJhbGciOiJSUzM4NCIsImtpZCI6Im15LWtleS1pZCJ9.eyJpc3MiOiJhdXRoMCJ9.ITNTVCT7ercumZKHV4-BXGkJwwa7fyF3CnSfEvm09fDFSkaseDxNo_75WLDmK9WM8RMHTPvkpHcTKm4guYEbC_la7RzFIKpU72bppzQojggSmWWXt_6zq50QP2t5HFMebote1zxhp8ccEdSCX5pyY6J2sm9kJ__HKK32KxIVCTjVCz-bFBS60oG35aYEySdKsxuUdWbD5FQ9I16Ony2x0EPvmlL3GPiAPmgjSFp3LtcBIbCDaoonM7iuDRGIQiDN_n2FKKb1Bt4_38uWPtTkwRpNalt6l53Y3JDdzGI5fMrMo3RQnQlAJxUJKD0eL6dRAA645IVIIXucHwuhgGGIVw";
    Algorithm algorithm = Algorithm.RSA384(provider);
    algorithm.verify(JWT.decode(jwt));
}
 
Example #30
Source File: RSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldPassRSA384VerificationWithProvidedPublicKey() throws Exception {
    RSAKeyProvider provider = mock(RSAKeyProvider.class);
    PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE, "RSA");
    when(provider.getPublicKeyById("my-key-id")).thenReturn((RSAPublicKey) publicKey);
    String jwt = "eyJhbGciOiJSUzM4NCIsImtpZCI6Im15LWtleS1pZCJ9.eyJpc3MiOiJhdXRoMCJ9.ITNTVCT7ercumZKHV4-BXGkJwwa7fyF3CnSfEvm09fDFSkaseDxNo_75WLDmK9WM8RMHTPvkpHcTKm4guYEbC_la7RzFIKpU72bppzQojggSmWWXt_6zq50QP2t5HFMebote1zxhp8ccEdSCX5pyY6J2sm9kJ__HKK32KxIVCTjVCz-bFBS60oG35aYEySdKsxuUdWbD5FQ9I16Ony2x0EPvmlL3GPiAPmgjSFp3LtcBIbCDaoonM7iuDRGIQiDN_n2FKKb1Bt4_38uWPtTkwRpNalt6l53Y3JDdzGI5fMrMo3RQnQlAJxUJKD0eL6dRAA645IVIIXucHwuhgGGIVw";
    Algorithm algorithm = Algorithm.RSA384(provider);
    algorithm.verify(JWT.decode(jwt));
}