use of com.microsoft.azure.keyvault.webkey.JsonWebKey in project azure-sdk-for-java by Azure.
the class AesValidationTests method octHashCode.
@Test
public void octHashCode() throws Exception {
JsonWebKey key = getAes();
// Compare hash codes for unequal JWK that would not map to the same hash
Assert.assertNotEquals(key.hashCode(), new JsonWebKey().withK(key.k()).hashCode());
Assert.assertNotEquals(key.hashCode(), new JsonWebKey().withKty(key.kty()).hashCode());
// Compare hash codes for unequal JWK that would map to the same hash
Assert.assertEquals(key.hashCode(), new JsonWebKey().withK(key.k()).withKty(key.kty()).hashCode());
}
use of com.microsoft.azure.keyvault.webkey.JsonWebKey in project azure-sdk-for-java by Azure.
the class RsaValidationTests method rsaPublicKeyValidation.
@Test
public void rsaPublicKeyValidation() throws Exception {
for (String keyStr : keys.values()) {
ObjectMapper mapper = new ObjectMapper();
JsonWebKey key = mapper.readValue(keyStr, JsonWebKey.class);
Assert.assertTrue(key.hasPrivateKey());
Assert.assertTrue(key.isValid());
KeyPair keyPair = key.toRSA();
validateRsaKey(keyPair, key);
Assert.assertNull(keyPair.getPrivate());
// Compare equal JSON web keys
JsonWebKey sameKey = mapper.readValue(keyStr, JsonWebKey.class);
Assert.assertEquals(key, key);
Assert.assertEquals(key, sameKey);
Assert.assertEquals(key.hashCode(), sameKey.hashCode());
}
}
use of com.microsoft.azure.keyvault.webkey.JsonWebKey in project azure-sdk-for-java by Azure.
the class RsaValidationTests method rsaPrivateKeyValidation.
@Test
public void rsaPrivateKeyValidation() throws Exception {
for (String keyStr : keys.values()) {
ObjectMapper mapper = new ObjectMapper();
JsonWebKey key = mapper.readValue(keyStr, JsonWebKey.class);
KeyPair keyPairWithPrivate = key.toRSA(true);
validateRsaKey(keyPairWithPrivate, key);
encryptDecrypt(keyPairWithPrivate.getPublic(), keyPairWithPrivate.getPrivate());
}
}
use of com.microsoft.azure.keyvault.webkey.JsonWebKey in project azure-sdk-for-java by Azure.
the class KeyOperationsTest method checkImportOperation.
private void checkImportOperation(KeyBundle keyBundle, boolean importToHardware) throws Exception {
Attributes attribute = new KeyAttributes().withEnabled(true).withExpires(new DateTime().withYear(2050).withMonthOfYear(1)).withNotBefore(new DateTime().withYear(2000).withMonthOfYear(1));
Map<String, String> tags = new HashMap<String, String>();
tags.put("foo", "baz");
JsonWebKey importedJwk = keyBundle.key();
KeyBundle importResultBundle = keyVaultClient.importKey(new ImportKeyRequest.Builder(getVaultUri(), KEY_NAME, keyBundle.key()).withHsm(importToHardware).withAttributes(attribute).withTags(tags).build());
validateRsaKeyBundle(importResultBundle, getVaultUri(), KEY_NAME, importToHardware ? JsonWebKeyType.RSA_HSM : JsonWebKeyType.RSA, importedJwk.keyOps(), attribute);
checkEncryptDecryptSequence(importedJwk, importResultBundle);
Assert.assertTrue(importResultBundle.key().isValid());
}
use of com.microsoft.azure.keyvault.webkey.JsonWebKey in project azure-sdk-for-java by Azure.
the class KeyOperationsTest method importKeyOperation.
@Test
public void importKeyOperation() throws Exception {
KeyBundle keyBundle = new KeyBundle();
JsonWebKey key = JsonWebKey.fromRSA(getTestKeyMaterial());
key.withKeyOps(Arrays.asList(JsonWebKeyOperation.ENCRYPT, JsonWebKeyOperation.DECRYPT));
keyBundle.withKey(key);
checkImportOperation(keyBundle, false);
checkImportOperation(keyBundle, true);
}
Aggregations