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);
}
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));
}
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();
}
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());
}
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());
}
Aggregations