Search in sources :

Example 11 with ECDSAKeyProvider

use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.

the class ECDSABouncyCastleProviderTests 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) ECDSAAlgorithmTest(com.auth0.jwt.algorithms.ECDSAAlgorithmTest) Test(org.junit.Test)

Example 12 with ECDSAKeyProvider

use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.

the class ECDSABouncyCastleProviderTests method shouldReturnNullSigningKeyIdIfCreatedWithDefaultProvider.

@Test
public void shouldReturnNullSigningKeyIdIfCreatedWithDefaultProvider() {
    ECPublicKey publicKey = mock(ECPublicKey.class);
    ECPrivateKey privateKey = mock(ECPrivateKey.class);
    ECDSAKeyProvider provider = ECDSAAlgorithm.providerForKeys(publicKey, privateKey);
    Algorithm algorithm = new ECDSAAlgorithm("some-alg", "some-algorithm", 32, provider);
    assertThat(algorithm.getSigningKeyId(), is(nullValue()));
}
Also used : ECPrivateKey(java.security.interfaces.ECPrivateKey) ECDSAKeyProvider(com.auth0.jwt.interfaces.ECDSAKeyProvider) ECPublicKey(java.security.interfaces.ECPublicKey) ECDSAAlgorithmTest(com.auth0.jwt.algorithms.ECDSAAlgorithmTest) Test(org.junit.Test)

Example 13 with ECDSAKeyProvider

use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.

the class ECDSABouncyCastleProviderTests method shouldDoECDSA384SigningWithProvidedPrivateKey.

@Test
public void shouldDoECDSA384SigningWithProvidedPrivateKey() throws Exception {
    ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
    PrivateKey privateKey = readPrivateKeyFromFile(PRIVATE_KEY_FILE_384, "EC");
    PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE_384, "EC");
    when(provider.getPrivateKey()).thenReturn((ECPrivateKey) privateKey);
    when(provider.getPublicKeyById(null)).thenReturn((ECPublicKey) publicKey);
    Algorithm algorithm = Algorithm.ECDSA384(provider);
    String jwt = asJWT(algorithm, ES384Header, 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) ECDSAAlgorithmTest(com.auth0.jwt.algorithms.ECDSAAlgorithmTest) Test(org.junit.Test)

Example 14 with ECDSAKeyProvider

use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.

the class AlgorithmTest method shouldThrowECDSA384InstanceWithNullKeyProvider.

@Test
public void shouldThrowECDSA384InstanceWithNullKeyProvider() {
    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("The Key Provider cannot be null.");
    ECDSAKeyProvider provider = null;
    Algorithm.ECDSA384(provider);
}
Also used : ECDSAKeyProvider(com.auth0.jwt.interfaces.ECDSAKeyProvider) Test(org.junit.Test)

Example 15 with ECDSAKeyProvider

use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.

the class AlgorithmTest method shouldCreateECDSA384AlgorithmWithProvider.

@Test
public void shouldCreateECDSA384AlgorithmWithProvider() {
    ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
    Algorithm algorithm = Algorithm.ECDSA384(provider);
    assertThat(algorithm, is(notNullValue()));
    assertThat(algorithm, is(instanceOf(ECDSAAlgorithm.class)));
    assertThat(algorithm.getDescription(), is("SHA384withECDSA"));
    assertThat(algorithm.getName(), is("ES384"));
}
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