use of com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation in project azure-sdk-for-java by Azure.
the class KeyVaultClientImpl method createKeyWithServiceResponseAsync.
/**
* Creates a new key, stores it, then returns key parameters and attributes to the client. The create key operation can be used to create any key type in Azure Key Vault. If the named key already exists, Azure Key Vault creates a new version of the key. Authorization: Requires the keys/create permission.
*
* @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
* @param keyName The name for the new key. The system will generate the version name for the new key.
* @param kty The type of key to create. For valid key types, see JsonWebKeyType. Supported JsonWebKey key types (kty) for Elliptic Curve, RSA, HSM, Octet. Possible values include: 'EC', 'RSA', 'RSA-HSM', 'oct'
* @return the observable to the KeyBundle object
*/
public Observable<ServiceResponse<KeyBundle>> createKeyWithServiceResponseAsync(String vaultBaseUrl, String keyName, JsonWebKeyType kty) {
if (vaultBaseUrl == null) {
throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
}
if (keyName == null) {
throw new IllegalArgumentException("Parameter keyName is required and cannot be null.");
}
if (this.apiVersion() == null) {
throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
}
if (kty == null) {
throw new IllegalArgumentException("Parameter kty is required and cannot be null.");
}
final Integer keySize = null;
final List<JsonWebKeyOperation> keyOps = null;
final KeyAttributes keyAttributes = null;
final Map<String, String> tags = null;
KeyCreateParameters parameters = new KeyCreateParameters();
parameters.withKty(kty);
parameters.withKeySize(null);
parameters.withKeyOps(null);
parameters.withKeyAttributes(null);
parameters.withTags(null);
String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
return service.createKey(keyName, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<KeyBundle>>>() {
@Override
public Observable<ServiceResponse<KeyBundle>> call(Response<ResponseBody> response) {
try {
ServiceResponse<KeyBundle> clientResponse = createKeyDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
use of com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation in project azure-sdk-for-java by Azure.
the class KeyVaultClientImpl method updateKeyWithServiceResponseAsync.
/**
* The update key operation changes specified attributes of a stored key and can be applied to any key type and key version stored in Azure Key Vault. The cryptographic material of a key itself cannot be changed. In order to perform this operation, the key must already exist in the Key Vault. Authorization: requires the keys/update permission.
*
* @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
* @param keyName The name of key to update.
* @param keyVersion The version of the key to update.
* @return the observable to the KeyBundle object
*/
public Observable<ServiceResponse<KeyBundle>> updateKeyWithServiceResponseAsync(String vaultBaseUrl, String keyName, String keyVersion) {
if (vaultBaseUrl == null) {
throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
}
if (keyName == null) {
throw new IllegalArgumentException("Parameter keyName is required and cannot be null.");
}
if (keyVersion == null) {
throw new IllegalArgumentException("Parameter keyVersion is required and cannot be null.");
}
if (this.apiVersion() == null) {
throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
}
final List<JsonWebKeyOperation> keyOps = null;
final KeyAttributes keyAttributes = null;
final Map<String, String> tags = null;
KeyUpdateParameters parameters = new KeyUpdateParameters();
parameters.withKeyOps(null);
parameters.withKeyAttributes(null);
parameters.withTags(null);
String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
return service.updateKey(keyName, keyVersion, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<KeyBundle>>>() {
@Override
public Observable<ServiceResponse<KeyBundle>> call(Response<ResponseBody> response) {
try {
ServiceResponse<KeyBundle> clientResponse = updateKeyDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
use of com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation in project azure-sdk-for-java by Azure.
the class RsaValidationTests method validateRsaKey.
private static void validateRsaKey(KeyPair keyPair, JsonWebKey key) throws Exception {
JsonWebKey jsonWebKey = JsonWebKey.fromRSA(keyPair);
boolean includePrivateKey = keyPair.getPrivate() != null;
KeyPair keyPair2 = jsonWebKey.toRSA(includePrivateKey);
Assert.assertTrue(includePrivateKey == jsonWebKey.hasPrivateKey());
PublicKey publicKey = keyPair2.getPublic();
PrivateKey privateKey = keyPair2.getPrivate();
if (includePrivateKey) {
Assert.assertNotNull(privateKey);
// set the missing properties to compare the keys
jsonWebKey.withKeyOps(new ArrayList<JsonWebKeyOperation>(key.keyOps()));
jsonWebKey.withKid(new String(key.kid()));
Assert.assertEquals(jsonWebKey, key);
Assert.assertEquals(key.hashCode(), jsonWebKey.hashCode());
}
encryptDecrypt(publicKey, privateKey);
}
use of com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation in project azure-sdk-for-java by Azure.
the class AesValidationTests method invalidKeyOps.
@Test
public void invalidKeyOps() throws Exception {
JsonWebKey key = getAes();
key.withKeyOps(Arrays.asList(JsonWebKeyOperation.ENCRYPT, new JsonWebKeyOperation("foo")));
Assert.assertFalse(key.isValid());
}
Aggregations