use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class ECDSAAlgorithmTest method shouldFailOnECDSA512SigningWhenProvidedPrivateKeyIsNull.
@Test
public void shouldFailOnECDSA512SigningWhenProvidedPrivateKeyIsNull() {
exception.expect(SignatureGenerationException.class);
exception.expectMessage("The Token's Signature couldn't be generated when signing using the Algorithm: SHA512withECDSA");
exception.expectCause(isA(IllegalStateException.class));
exception.expectCause(hasMessage(is("The given Private Key is null.")));
ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
when(provider.getPrivateKey()).thenReturn(null);
Algorithm algorithm = Algorithm.ECDSA512(provider);
algorithm.sign(new byte[0], new byte[0]);
}
use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class ECDSAAlgorithmTest method shouldFailOnECDSA384SigningWhenProvidedPrivateKeyIsNull.
@Test
public void shouldFailOnECDSA384SigningWhenProvidedPrivateKeyIsNull() {
exception.expect(SignatureGenerationException.class);
exception.expectMessage("The Token's Signature couldn't be generated when signing using the Algorithm: SHA384withECDSA");
exception.expectCause(isA(IllegalStateException.class));
exception.expectCause(hasMessage(is("The given Private Key is null.")));
ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
when(provider.getPrivateKey()).thenReturn(null);
Algorithm algorithm = Algorithm.ECDSA384(provider);
algorithm.sign(new byte[0], new byte[0]);
}
use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class ECDSAAlgorithmTest method shouldPassECDSA384VerificationWithProvidedPublicKey.
@Test
public void shouldPassECDSA384VerificationWithProvidedPublicKey() throws Exception {
ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE_384, "EC");
when(provider.getPublicKeyById("my-key-id")).thenReturn((ECPublicKey) publicKey);
String jwt = "eyJhbGciOiJFUzM4NCIsImtpZCI6Im15LWtleS1pZCJ9.eyJpc3MiOiJhdXRoMCJ9.9kjGuFTPx3ylfpqL0eY9H7TGmPepjQOBKI8UPoEvby6N7dDLF5HxLohosNxxFymNT7LzpeSgOPAB0wJEwG2Nl2ukgdUOpZOf492wog_i5ZcZmAykd3g1QH7onrzd69GU";
Algorithm algorithm = Algorithm.ECDSA384(provider);
algorithm.verify(JWT.decode(jwt));
}
use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class ECDSAAlgorithmTest method shouldReturnSigningKeyIdFromProvider.
@Test
public void shouldReturnSigningKeyIdFromProvider() {
ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
when(provider.getPrivateKeyId()).thenReturn("keyId");
Algorithm algorithm = new ECDSAAlgorithm("some-alg", "some-algorithm", 32, provider);
assertThat(algorithm.getSigningKeyId(), is("keyId"));
}
use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class ECDSAAlgorithmTest method shouldFailECDSA384VerificationWhenProvidedPublicKeyIsNull.
@Test
public void shouldFailECDSA384VerificationWhenProvidedPublicKeyIsNull() {
exception.expect(SignatureVerificationException.class);
exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA384withECDSA");
exception.expectCause(isA(IllegalStateException.class));
exception.expectCause(hasMessage(is("The given Public Key is null.")));
ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
when(provider.getPublicKeyById("my-key-id")).thenReturn(null);
String jwt = "eyJhbGciOiJFUzM4NCIsImtpZCI6Im15LWtleS1pZCJ9.eyJpc3MiOiJhdXRoMCJ9.9kjGuFTPx3ylfpqL0eY9H7TGmPepjQOBKI8UPoEvby6N7dDLF5HxLohosNxxFymNT7LzpeSgOPAB0wJEwG2Nl2ukgdUOpZOf492wog_i5ZcZmAykd3g1QH7onrzd69GU";
Algorithm algorithm = Algorithm.ECDSA384(provider);
algorithm.verify(JWT.decode(jwt));
}
Aggregations