use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class AlgorithmTest method shouldThrowECDSA256InstanceWithNullKeyProvider.
@Test
public void shouldThrowECDSA256InstanceWithNullKeyProvider() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("The Key Provider cannot be null.");
ECDSAKeyProvider provider = null;
Algorithm.ECDSA256(provider);
}
use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class AlgorithmTest method shouldCreateECDSA256AlgorithmWithProvider.
@Test
public void shouldCreateECDSA256AlgorithmWithProvider() {
ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
Algorithm algorithm = Algorithm.ECDSA256(provider);
assertThat(algorithm, is(notNullValue()));
assertThat(algorithm, is(instanceOf(ECDSAAlgorithm.class)));
assertThat(algorithm.getDescription(), is("SHA256withECDSA"));
assertThat(algorithm.getName(), is("ES256"));
}
use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class AlgorithmTest method shouldCreateECDSA512AlgorithmWithProvider.
@Test
public void shouldCreateECDSA512AlgorithmWithProvider() {
ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
Algorithm algorithm = Algorithm.ECDSA512(provider);
assertThat(algorithm, is(notNullValue()));
assertThat(algorithm, is(instanceOf(ECDSAAlgorithm.class)));
assertThat(algorithm.getDescription(), is("SHA512withECDSA"));
assertThat(algorithm.getName(), is("ES512"));
}
use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class ECDSAAlgorithmTest method shouldDoECDSA512SigningWithProvidedPrivateKey.
@Test
public void shouldDoECDSA512SigningWithProvidedPrivateKey() throws Exception {
ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
PrivateKey privateKey = readPrivateKeyFromFile(PRIVATE_KEY_FILE_512, "EC");
PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC");
when(provider.getPrivateKey()).thenReturn((ECPrivateKey) privateKey);
when(provider.getPublicKeyById(null)).thenReturn((ECPublicKey) publicKey);
Algorithm algorithm = Algorithm.ECDSA512(provider);
String jwt = asJWT(algorithm, ES512Header, auth0IssPayload);
assertSignaturePresent(jwt);
algorithm.verify(JWT.decode(jwt));
}
use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class ECDSAAlgorithmTest method shouldFailOnECDSA256SigningWhenProvidedPrivateKeyIsNull.
@Test
public void shouldFailOnECDSA256SigningWhenProvidedPrivateKeyIsNull() {
exception.expect(SignatureGenerationException.class);
exception.expectMessage("The Token's Signature couldn't be generated when signing using the Algorithm: SHA256withECDSA");
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.ECDSA256(provider);
algorithm.sign(new byte[0], new byte[0]);
}
Aggregations