use of com.microsoft.azure.keyvault.models.KeyBundle 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);
}
use of com.microsoft.azure.keyvault.models.KeyBundle in project azure-sdk-for-java by Azure.
the class KeyOperationsTest method importTestKey.
private static JsonWebKey importTestKey() throws Exception {
KeyBundle keyBundle = new KeyBundle();
JsonWebKey key = JsonWebKey.fromRSA(getTestKeyMaterial());
key.withKty(JsonWebKeyType.RSA);
key.withKeyOps(Arrays.asList(JsonWebKeyOperation.ENCRYPT, JsonWebKeyOperation.DECRYPT, JsonWebKeyOperation.SIGN, JsonWebKeyOperation.VERIFY, JsonWebKeyOperation.WRAP_KEY, JsonWebKeyOperation.UNWRAP_KEY));
keyBundle = keyVaultClient.importKey(new ImportKeyRequest.Builder(getVaultUri(), KEY_NAME, key).withHsm(false).build());
validateRsaKeyBundle(keyBundle, getVaultUri(), KEY_NAME, JsonWebKeyType.RSA, null, null);
return keyBundle.key();
}
use of com.microsoft.azure.keyvault.models.KeyBundle in project azure-sdk-for-java by Azure.
the class KeyOperationsTest method listKeys.
@Test
public void listKeys() throws Exception {
HashSet<String> keys = new HashSet<String>();
for (int i = 0; i < MAX_KEYS; ++i) {
int failureCount = 0;
for (; ; ) {
try {
KeyBundle createdBundle = keyVaultClient.createKey(new CreateKeyRequest.Builder(getVaultUri(), KEY_NAME + i, JsonWebKeyType.RSA).build());
KeyIdentifier kid = new KeyIdentifier(createdBundle.key().kid());
keys.add(kid.baseIdentifier());
break;
} catch (KeyVaultErrorException e) {
++failureCount;
if (e.body().error().code().equals("Throttled")) {
System.out.println("Waiting to avoid throttling");
Thread.sleep(failureCount * 1500);
continue;
}
throw e;
}
}
}
PagedList<KeyItem> listResult = keyVaultClient.listKeys(getVaultUri(), PAGELIST_MAX_KEYS);
Assert.assertTrue(PAGELIST_MAX_KEYS >= listResult.currentPage().items().size());
HashSet<String> toDelete = new HashSet<String>();
for (KeyItem item : listResult) {
if (item != null) {
KeyIdentifier id = new KeyIdentifier(item.kid());
toDelete.add(id.name());
keys.remove(item.kid());
}
}
Assert.assertEquals(0, keys.size());
for (String name : toDelete) {
try {
keyVaultClient.deleteKey(getVaultUri(), name);
} catch (KeyVaultErrorException e) {
// Ignore forbidden exception for certificate keys that cannot be deleted
if (!e.body().error().code().equals("Forbidden"))
throw e;
}
}
}
Aggregations