Search in sources :

Example 1 with JsonWebKey

use of com.microsoft.azure.keyvault.webkey.JsonWebKey in project azure-sdk-for-java by Azure.

the class AesValidationTests method serializeDeserialize.

private static JsonWebKey serializeDeserialize(SecretKey skey) throws Exception {
    JsonWebKey webKey = JsonWebKey.fromAes(skey);
    String serializedKey = webKey.toString();
    ObjectMapper mapper = new ObjectMapper();
    return mapper.readValue(serializedKey, JsonWebKey.class);
}
Also used : JsonWebKey(com.microsoft.azure.keyvault.webkey.JsonWebKey) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with JsonWebKey

use of com.microsoft.azure.keyvault.webkey.JsonWebKey in project azure-sdk-for-java by Azure.

the class ClearMemoryTests method clearMemory.

@Test
public void clearMemory() {
    JsonWebKey key = new JsonWebKey().withD(getRandomByte()).withDp(getRandomByte()).withDq(getRandomByte()).withE(getRandomByte()).withK(getRandomByte()).withN(getRandomByte()).withP(getRandomByte()).withQ(getRandomByte()).withQi(getRandomByte()).withT(getRandomByte());
    key.clearMemory();
    Assert.assertNull(key.d());
    Assert.assertNull(key.dp());
    Assert.assertNull(key.dq());
    Assert.assertNull(key.e());
    Assert.assertNull(key.k());
    Assert.assertNull(key.n());
    Assert.assertNull(key.p());
    Assert.assertNull(key.q());
    Assert.assertNull(key.qi());
    Assert.assertNull(key.t());
    // Compare it with a newly created JsonWebKey with no properties set.
    JsonWebKey key2 = new JsonWebKey();
    Assert.assertTrue(key2.equals(key));
}
Also used : JsonWebKey(com.microsoft.azure.keyvault.webkey.JsonWebKey) Test(org.junit.Test)

Example 3 with JsonWebKey

use of com.microsoft.azure.keyvault.webkey.JsonWebKey in project azure-sdk-for-java by Azure.

the class ClearMemoryTests method clearNullMemory.

@Test
public void clearNullMemory() {
    JsonWebKey key = new JsonWebKey();
    key.clearMemory();
}
Also used : JsonWebKey(com.microsoft.azure.keyvault.webkey.JsonWebKey) Test(org.junit.Test)

Example 4 with JsonWebKey

use of com.microsoft.azure.keyvault.webkey.JsonWebKey in project azure-sdk-for-java by Azure.

the class RsaHsmValidationTests method rsaHsmValidation.

@Test
public void rsaHsmValidation() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    JsonWebKey keyNoT = mapper.readValue(keyWithoutT, JsonWebKey.class);
    JsonWebKey keyT = mapper.readValue(keyWithT, JsonWebKey.class);
    Assert.assertTrue(keyNoT.isValid());
    Assert.assertFalse(keyNoT.hasPrivateKey());
    Assert.assertTrue(keyT.isValid());
    Assert.assertFalse(keyT.hasPrivateKey());
}
Also used : JsonWebKey(com.microsoft.azure.keyvault.webkey.JsonWebKey) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with JsonWebKey

use of com.microsoft.azure.keyvault.webkey.JsonWebKey in project azure-sdk-for-java by Azure.

the class RsaHsmValidationTests method rsaHsmHashCode.

@Test
public void rsaHsmHashCode() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    JsonWebKey keyNoT = mapper.readValue(keyWithoutT, JsonWebKey.class);
    JsonWebKey keyT = mapper.readValue(keyWithT, JsonWebKey.class);
    Assert.assertNotEquals(keyT.hashCode(), keyNoT.hashCode());
    // Compare hash codes for unequal JWK that would not map to the same hash
    Assert.assertNotEquals(keyT.hashCode(), new JsonWebKey().withKid(keyT.kid()).withT(keyT.t()).hashCode());
    Assert.assertNotEquals(keyT.hashCode(), new JsonWebKey().withKid(keyT.kid()).withKty(keyT.kty()).hashCode());
    Assert.assertNotEquals(keyNoT.hashCode(), new JsonWebKey().hashCode());
    // Compare hash codes for unequal JWK that would map to the same hash
    Assert.assertEquals(keyT.hashCode(), new JsonWebKey().withKid(keyT.kid()).withKty(keyT.kty()).withT(keyT.t()).hashCode());
    Assert.assertEquals(keyNoT.hashCode(), new JsonWebKey().withKid(keyT.kid()).hashCode());
}
Also used : JsonWebKey(com.microsoft.azure.keyvault.webkey.JsonWebKey) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

JsonWebKey (com.microsoft.azure.keyvault.webkey.JsonWebKey)19 Test (org.junit.Test)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 KeyIdentifier (com.microsoft.azure.keyvault.KeyIdentifier)3 KeyBundle (com.microsoft.azure.keyvault.models.KeyBundle)3 KeyOperationResult (com.microsoft.azure.keyvault.models.KeyOperationResult)3 KeyPair (java.security.KeyPair)3 Random (java.util.Random)3 JsonWebKeyOperation (com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation)2 RsaKey (com.microsoft.azure.keyvault.cryptography.RsaKey)1 Attributes (com.microsoft.azure.keyvault.models.Attributes)1 KeyAttributes (com.microsoft.azure.keyvault.models.KeyAttributes)1 KeyVerifyResult (com.microsoft.azure.keyvault.models.KeyVerifyResult)1 ImportKeyRequest (com.microsoft.azure.keyvault.requests.ImportKeyRequest)1 MessageDigest (java.security.MessageDigest)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1 HashMap (java.util.HashMap)1 KeyGenerator (javax.crypto.KeyGenerator)1 SecretKey (javax.crypto.SecretKey)1