Search in sources :

Example 16 with ECDSAKeyProvider

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);
}
Also used : ECDSAKeyProvider(com.auth0.jwt.interfaces.ECDSAKeyProvider) Test(org.junit.Test)

Example 17 with ECDSAKeyProvider

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"));
}
Also used : ECDSAKeyProvider(com.auth0.jwt.interfaces.ECDSAKeyProvider) Test(org.junit.Test)

Example 18 with ECDSAKeyProvider

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"));
}
Also used : ECDSAKeyProvider(com.auth0.jwt.interfaces.ECDSAKeyProvider) Test(org.junit.Test)

Example 19 with ECDSAKeyProvider

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));
}
Also used : ECDSAKeyProvider(com.auth0.jwt.interfaces.ECDSAKeyProvider) ECPrivateKey(java.security.interfaces.ECPrivateKey) ECPublicKey(java.security.interfaces.ECPublicKey) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 20 with ECDSAKeyProvider

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]);
}
Also used : ECDSAKeyProvider(com.auth0.jwt.interfaces.ECDSAKeyProvider) Test(org.junit.Test)

Aggregations

ECDSAKeyProvider (com.auth0.jwt.interfaces.ECDSAKeyProvider)58 Test (org.junit.Test)58 ECPublicKey (java.security.interfaces.ECPublicKey)30 ECPrivateKey (java.security.interfaces.ECPrivateKey)26 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)26 ECDSAAlgorithmTest (com.auth0.jwt.algorithms.ECDSAAlgorithmTest)23 BigInteger (java.math.BigInteger)6 ECParameterSpec (java.security.spec.ECParameterSpec)6