Class KeyAsyncClient
- java.lang.Object
-
- com.azure.security.keyvault.keys.KeyAsyncClient
-
public final class KeyAsyncClient extends Object
TheKeyAsyncClientprovides asynchronous methods to managekeysin the Azure Key Vault. The client supports creating, retrieving, updating, deleting, purging, backing up, restoring and listing thekeys. The client also supports listingdeleted keysfor a soft-delete enabled Azure Key Vault.Samples to construct the async client
KeyAsyncClient keyAsyncClient = new KeyClientBuilder() .vaultUrl("https://myvault.azure.net/") .credential(new DefaultAzureCredentialBuilder().build()) .buildAsyncClient();- See Also:
KeyClientBuilder,PagedFlux
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Mono<byte[]>backupKey(String name)Requests a backup of the specifiedkeybe downloaded to the client.Mono<com.azure.core.http.rest.Response<byte[]>>backupKeyWithResponse(String name)Requests a backup of the specifiedkeybe downloaded to the client.com.azure.core.util.polling.PollerFlux<DeletedKey,Void>beginDeleteKey(String name)Deletes akeyof any type from the key vault.com.azure.core.util.polling.PollerFlux<KeyVaultKey,Void>beginRecoverDeletedKey(String name)Recovers thedeleted keyin the key vault to its latest version and can only be performed on a soft-delete enabled vault.Mono<KeyVaultKey>createEcKey(CreateEcKeyOptions createEcKeyOptions)Creates a newEC keyand stores it in the key vault.Mono<com.azure.core.http.rest.Response<KeyVaultKey>>createEcKeyWithResponse(CreateEcKeyOptions createEcKeyOptions)Creates a newEC keyand stores it in the key vault.Mono<KeyVaultKey>createKey(CreateKeyOptions createKeyOptions)Creates a newkeyand stores it in the key vault.Mono<KeyVaultKey>createKey(String name, KeyType keyType)Creates a newkeyand stores it in the key vault.Mono<com.azure.core.http.rest.Response<KeyVaultKey>>createKeyWithResponse(CreateKeyOptions createKeyOptions)Creates a newkeyand stores it in the key vault.Mono<KeyVaultKey>createOctKey(CreateOctKeyOptions createOctKeyOptions)Creates and stores a newsymmetric keyin the key vault.Mono<com.azure.core.http.rest.Response<KeyVaultKey>>createOctKeyWithResponse(CreateOctKeyOptions createOctKeyOptions)Creates and stores a newsymmetric keyin the key vault.Mono<KeyVaultKey>createRsaKey(CreateRsaKeyOptions createRsaKeyOptions)/** Creates a newRSA keyand stores it in the key vault.Mono<com.azure.core.http.rest.Response<KeyVaultKey>>createRsaKeyWithResponse(CreateRsaKeyOptions createRsaKeyOptions)Creates a newRSA keyand stores it in the key vault.Mono<DeletedKey>getDeletedKey(String name)Gets the public part of adeleted key.Mono<com.azure.core.http.rest.Response<DeletedKey>>getDeletedKeyWithResponse(String name)Gets the public part of adeleted key.Mono<KeyVaultKey>getKey(String name)Gets the public part of the specifiedkeyand key version.Mono<KeyVaultKey>getKey(String name, String version)Gets the public part of the specifiedkeyand key version.Mono<com.azure.core.http.rest.Response<KeyVaultKey>>getKeyWithResponse(String name, String version)Gets the public part of the specifiedkeyand key version.StringgetVaultUrl()Get the vault endpoint url to which service requests are sent to.Mono<KeyVaultKey>importKey(ImportKeyOptions importKeyOptions)Imports an externally createdkeyand stores it in the key vault.Mono<KeyVaultKey>importKey(String name, JsonWebKey keyMaterial)Imports an externally createdkeyand stores it in the key vault.Mono<com.azure.core.http.rest.Response<KeyVaultKey>>importKeyWithResponse(ImportKeyOptions importKeyOptions)Imports an externally createdkeyand stores it in the key vault.com.azure.core.http.rest.PagedFlux<DeletedKey>listDeletedKeys()Listsdeleted keysof the key vault.com.azure.core.http.rest.PagedFlux<KeyProperties>listPropertiesOfKeys()Listkeysin the key vault.com.azure.core.http.rest.PagedFlux<KeyProperties>listPropertiesOfKeyVersions(String name)List all versions of the specifiedkeys.Mono<Void>purgeDeletedKey(String name)Permanently deletes the specifiedkeywithout the possibility of recovery.Mono<com.azure.core.http.rest.Response<Void>>purgeDeletedKeyWithResponse(String name)Permanently deletes the specifiedkeywithout the possibility of recovery.Mono<KeyVaultKey>restoreKeyBackup(byte[] backup)Restores a backed upkeyto a vault.Mono<com.azure.core.http.rest.Response<KeyVaultKey>>restoreKeyBackupWithResponse(byte[] backup)Restores a backed upkeyto a vault.Mono<KeyVaultKey>updateKeyProperties(KeyProperties keyProperties, KeyOperation... keyOperations)Updates theattributesandkey operationsassociated with the specifiedkey, but not the cryptographic key material of the specifiedkeyin the key vault.Mono<com.azure.core.http.rest.Response<KeyVaultKey>>updateKeyPropertiesWithResponse(KeyProperties keyProperties, KeyOperation... keyOperations)Updates theattributesandkey operationsassociated with the specifiedkey, but not the cryptographic key material of the specifiedkeyin the key vault.
-
-
-
Method Detail
-
getVaultUrl
public String getVaultUrl()
Get the vault endpoint url to which service requests are sent to.- Returns:
- The vault endpoint url
-
createKey
public Mono<KeyVaultKey> createKey(String name, KeyType keyType)
Creates a newkeyand stores it in the key vault. The create key operation can be used to create anykeyTypein Azure Key Vault. If akeywith the provided name already exists, Azure Key Vault creates a new version of thekey. It requires thekeys/createpermission.The
keyTypeindicates the type ofkeyto create. Possible values include:EC,EC-HSM,RSA,RSA-HSM,OCTandOCT-HSM.Code Samples
Creates a new
EC key. Subscribes to the call asynchronously and prints out the newlycreated keydetails when a response has been received.keyAsyncClient.createKey("keyName", KeyType.EC) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(key -> System.out.printf("Created key with name: %s and id: %s %n", key.getName(), key.getId()));- Parameters:
name- The name of thekeybeing created.keyType- The type ofkeyto create. For valid values, seeKeyType.- Returns:
- A
Monocontaining thecreated key. - Throws:
com.azure.core.exception.HttpResponseException- Ifnameis an empty string.NullPointerException- IfnameorkeyTypearenull.
-
createKeyWithResponse
public Mono<com.azure.core.http.rest.Response<KeyVaultKey>> createKeyWithResponse(CreateKeyOptions createKeyOptions)
Creates a newkeyand stores it in the key vault. The create key operation can be used to create anykeyTypein Azure Key Vault. If akeywith the provided name already exists, Azure Key Vault creates a new version of thekey. It requires thekeys/createpermission.The
keyTypeindicates the type ofkeyto create. Possible values include:EC,EC-HSM,RSA,RSA-HSM,OCTandOCT-HSM.Code Samples
Creates a new
EC key. Subscribes to the call asynchronously and prints out the newlycreated keydetails when a response has been received.CreateKeyOptions createKeyOptions = new CreateKeyOptions("keyName", KeyType.RSA) .setNotBefore(OffsetDateTime.now().plusDays(1)) .setExpiresOn(OffsetDateTime.now().plusYears(1)); keyAsyncClient.createKeyWithResponse(createKeyOptions) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(createKeyResponse -> System.out.printf("Created key with name: %s and: id %s%n", createKeyResponse.getValue().getName(), createKeyResponse.getValue().getId()));- Parameters:
createKeyOptions- Theoptions objectcontaining information about thekeybeing created.- Returns:
- A
Monocontaining aResponsewhosevaluecontains thecreated key. - Throws:
com.azure.core.exception.HttpResponseException- IfCreateKeyOptions.getName()is an empty string.NullPointerException- IfnameorkeyTypearenull.com.azure.core.exception.ResourceModifiedException- IfcreateKeyOptionsis malformed.
-
createKey
public Mono<KeyVaultKey> createKey(CreateKeyOptions createKeyOptions)
Creates a newkeyand stores it in the key vault. The create key operation can be used to create anykeyTypein Azure Key Vault. If akeywith the provided name already exists, Azure Key Vault creates a new version of thekey. It requires thekeys/createpermission.The
CreateKeyOptionsparameter is required. TheexpiresandnotBeforevalues are optional. Theenabledfield is set totrueby Azure Key Vault, if not specified.The
keyTypeindicates the type ofkeyto create. Possible values include:EC,EC-HSM,RSA,RSA-HSM,OCTandOCT-HSM.Code Samples
Creates a new
RSA keywhich activates in one day and expires in one year. Subscribes to the call asynchronously and prints out the newlycreated keydetails when a response has been received.CreateKeyOptions createKeyOptions = new CreateKeyOptions("keyName", KeyType.RSA) .setNotBefore(OffsetDateTime.now().plusDays(1)) .setExpiresOn(OffsetDateTime.now().plusYears(1)); keyAsyncClient.createKey(createKeyOptions) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(key -> System.out.printf("Created key with name: %s and id: %s %n", key.getName(), key.getId()));- Parameters:
createKeyOptions- Theoptions objectcontaining information about thekeybeing created.- Returns:
- A
Monocontaining thecreated key. - Throws:
com.azure.core.exception.HttpResponseException- IfCreateKeyOptions.getName()is an empty string.NullPointerException- IfcreateKeyOptionsisnull.com.azure.core.exception.ResourceModifiedException- IfcreateKeyOptionsis malformed.
-
createRsaKey
public Mono<KeyVaultKey> createRsaKey(CreateRsaKeyOptions createRsaKeyOptions)
/** Creates a newRSA keyand stores it in the key vault. The create RSA key operation can be used to create any RSA key type in Azure Key Vault. If akeywith the provided name already exists, Azure Key Vault creates a new version of thekey. It requires thekeys/createpermission.The
CreateRsaKeyOptionsparameter is required. ThekeySizecan be optionally specified. TheexpiresandnotBeforevalues are optional. Theenabledfield is set totrueby Azure Key Vault, if not specified.The
keyTypeindicates the type ofkeyto create. Possible values include:RSAandRSA-HSM.Code Samples
Creates a new
RSA keywith size 2048 which activates in one day and expires in one year. Subscribes to the call asynchronously and prints out the newlycreated keydetails when a response has been received.CreateRsaKeyOptions createRsaKeyOptions = new CreateRsaKeyOptions("keyName") .setKeySize(2048) .setNotBefore(OffsetDateTime.now().plusDays(1)) .setExpiresOn(OffsetDateTime.now().plusYears(1)); keyAsyncClient.createRsaKey(createRsaKeyOptions) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(rsaKey -> System.out.printf("Created key with name: %s and id: %s %n", rsaKey.getName(), rsaKey.getId()));- Parameters:
createRsaKeyOptions- Theoptions objectcontaining information about theRSA keybeing created.- Returns:
- A
Monocontaining thecreated key. - Throws:
com.azure.core.exception.HttpResponseException- IfCreateKeyOptions.getName()is an empty string.NullPointerException- IfcreateRsaKeyOptionsisnull.com.azure.core.exception.ResourceModifiedException- IfcreateRsaKeyOptionsis malformed.
-
createRsaKeyWithResponse
public Mono<com.azure.core.http.rest.Response<KeyVaultKey>> createRsaKeyWithResponse(CreateRsaKeyOptions createRsaKeyOptions)
Creates a newRSA keyand stores it in the key vault. The create RSA key operation can be used to create any RSA key type in Azure Key Vault. If akeywith the provided name already exists, Azure Key Vault creates a new version of thekey. It requires thekeys/createpermission.The
CreateRsaKeyOptionsparameter is required. ThekeySizecan be optionally specified. TheexpiresandnotBeforevalues are optional. Theenabledfield is set totrueby Azure Key Vault, if not specified.The
keyTypeindicates the type ofkeyto create. Possible values include:RSAandRSA-HSM.Code Samples
Creates a new
RSA keywith size 2048 which activates in one day and expires in one year. Subscribes to the call asynchronously and prints out the newlycreated keydetails when a response has been received.CreateRsaKeyOptions createRsaKeyOptions = new CreateRsaKeyOptions("keyName") .setKeySize(2048) .setNotBefore(OffsetDateTime.now().plusDays(1)) .setExpiresOn(OffsetDateTime.now().plusYears(1)); keyAsyncClient.createRsaKeyWithResponse(createRsaKeyOptions) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(createRsaKeyResponse -> System.out.printf("Created key with name: %s and: id %s%n", createRsaKeyResponse.getValue().getName(), createRsaKeyResponse.getValue().getId()));- Parameters:
createRsaKeyOptions- Theoptions objectcontaining information about theRSA keybeing created.- Returns:
- A
Monocontaining aResponsewhosevaluecontains thecreated key. - Throws:
com.azure.core.exception.HttpResponseException- IfCreateKeyOptions.getName()is an empty string.NullPointerException- IfcreateRsaKeyOptionsisnull.com.azure.core.exception.ResourceModifiedException- IfcreateRsaKeyOptionsis malformed.
-
createEcKey
public Mono<KeyVaultKey> createEcKey(CreateEcKeyOptions createEcKeyOptions)
Creates a newEC keyand stores it in the key vault. The create EC key operation can be used to create any ECkey typein Azure Key Vault. If akeywith the provided name already exists, Azure Key Vault creates a new version of thekey. It requires thekeys/createpermission.The
CreateEcKeyOptionsparameter is required. Thekey curvecan be optionally specified. If not specified, the default valueP-256is used by Azure Key Vault. TheexpiresandnotBeforevalues are optional. Theenabledfield is set totrueby Azure Key Vault, if not specified.The
keyTypeindicates the type ofKeyVaultKeykey to create. Possible values include:ECandEC-HSM.Code Samples
Creates a new
EC keywith aP-384web key curve. The key activates in one day and expires in one year. Subscribes to the call asynchronously and prints out the newlycreated keydetails when a response has been received.CreateEcKeyOptions createEcKeyOptions = new CreateEcKeyOptions("keyName") .setCurveName(KeyCurveName.P_384) .setNotBefore(OffsetDateTime.now().plusDays(1)) .setExpiresOn(OffsetDateTime.now().plusYears(1)); keyAsyncClient.createEcKey(createEcKeyOptions) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(ecKey -> System.out.printf("Created key with name: %s and id: %s %n", ecKey.getName(), ecKey.getId()));- Parameters:
createEcKeyOptions- Theoptions objectcontaining information about theEC keybeing created.- Returns:
- A
Monocontaining thecreated key. - Throws:
com.azure.core.exception.HttpResponseException- IfCreateKeyOptions.getName()is an empty string.NullPointerException- IfecKeyCreateOptionsisnull.com.azure.core.exception.ResourceModifiedException- IfecKeyCreateOptionsis malformed.
-
createEcKeyWithResponse
public Mono<com.azure.core.http.rest.Response<KeyVaultKey>> createEcKeyWithResponse(CreateEcKeyOptions createEcKeyOptions)
Creates a newEC keyand stores it in the key vault. The create EC key operation can be used to create any ECkey typein Azure Key Vault. If akeywith the provided name already exists, Azure Key Vault creates a new version of thekey. It requires thekeys/createpermission.The
CreateEcKeyOptionsparameter is required. Thekey curvecan be optionally specified. If not specified, the default valueP-256is used by Azure Key Vault. TheexpiresandnotBeforevalues are optional. Theenabledfield is set totrueby Azure Key Vault, if not specified.The
keyTypeindicates the type ofKeyVaultKeykey to create. Possible values include:ECandEC-HSM.Code Samples
Creates a new
EC keywith aP-384web key curve. The key activates in one day and expires in one year. Subscribes to the call asynchronously and prints out the newlycreated keydetails when a response has been received.CreateEcKeyOptions createEcKeyOptions = new CreateEcKeyOptions("keyName") .setCurveName(KeyCurveName.P_384) .setNotBefore(OffsetDateTime.now().plusDays(1)) .setExpiresOn(OffsetDateTime.now().plusYears(1)); keyAsyncClient.createEcKeyWithResponse(createEcKeyOptions) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(createEcKeyResponse -> System.out.printf("Created key with name: %s and: id %s%n", createEcKeyResponse.getValue().getName(), createEcKeyResponse.getValue().getId()));- Parameters:
createEcKeyOptions- Theoptions objectcontaining information about theEC keybeing created.- Returns:
- A
Monocontaining aResponsewhosevaluecontains thecreated key. - Throws:
com.azure.core.exception.HttpResponseException- IfCreateKeyOptions.getName()is an empty string.NullPointerException- IfecKeyCreateOptionsisnull.com.azure.core.exception.ResourceModifiedException- IfecKeyCreateOptionsis malformed.
-
createOctKey
public Mono<KeyVaultKey> createOctKey(CreateOctKeyOptions createOctKeyOptions)
Creates and stores a newsymmetric keyin the key vault. If akeywith the provided name already exists, Azure Key Vault creates a new version of the key. This operation requires thekeys/createpermission.The
CreateOctKeyOptionsparameter is required. TheexpiresandnotBeforevalues are optional. Theenabledfield is set totrueby Azure Key Vault, if not specified.The
keyTypeindicates the type ofKeyVaultKeykey to create. Possible values include:OCTandOCT-HSM.Code Samples
Creates a new
symmetric key. Thekeyactivates in one day and expires in one year. Subscribes to the call asynchronously and prints out the details of the newlycreated keywhen a response has been received.CreateOctKeyOptions createOctKeyOptions = new CreateOctKeyOptions("keyName") .setNotBefore(OffsetDateTime.now().plusDays(1)) .setExpiresOn(OffsetDateTime.now().plusYears(1)); keyAsyncClient.createOctKey(createOctKeyOptions) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(octKey -> System.out.printf("Created key with name: %s and id: %s %n", octKey.getName(), octKey.getId()));- Parameters:
createOctKeyOptions- Theoptions objectcontaining information about thesymmetric keybeing created.- Returns:
- A
Monocontaining thecreated key. - Throws:
com.azure.core.exception.HttpResponseException- IfCreateKeyOptions.getName()is an empty string.NullPointerException- IfecKeyCreateOptionsisnull.com.azure.core.exception.ResourceModifiedException- IfecKeyCreateOptionsis malformed.
-
createOctKeyWithResponse
public Mono<com.azure.core.http.rest.Response<KeyVaultKey>> createOctKeyWithResponse(CreateOctKeyOptions createOctKeyOptions)
Creates and stores a newsymmetric keyin the key vault. If akeywith the provided name already exists, Azure Key Vault creates a new version of the key. This operation requires thekeys/createpermission.The
CreateOctKeyOptionsparameter is required. TheexpiresandnotBeforevalues are optional. Theenabledfield is set totrueby Azure Key Vault, if not specified.The
keyTypeindicates the type ofKeyVaultKeykey to create. Possible values include:OCTandOCT-HSM.Code Samples
Creates a new
symmetric key. Thekeyactivates in one day and expires in one year. Subscribes to the call asynchronously and prints out the details of the newlycreated keywhen a response has been received.CreateOctKeyOptions createOctKeyOptions = new CreateOctKeyOptions("keyName") .setNotBefore(OffsetDateTime.now().plusDays(1)) .setExpiresOn(OffsetDateTime.now().plusYears(1)); keyAsyncClient.createOctKeyWithResponse(createOctKeyOptions) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(createOctKeyResponse -> System.out.printf("Created key with name: %s and: id %s%n", createOctKeyResponse.getValue().getName(), createOctKeyResponse.getValue().getId()));- Parameters:
createOctKeyOptions- Theoptions objectcontaining information about thesymmetric keybeing created.- Returns:
- A
Monocontaining aResponsewhosevaluecontains thecreated key. - Throws:
com.azure.core.exception.HttpResponseException- IfCreateKeyOptions.getName()is an empty string.NullPointerException- IfcreateOctKeyOptionsisnull.com.azure.core.exception.ResourceModifiedException- IfcreateOctKeyOptionsis malformed.
-
importKey
public Mono<KeyVaultKey> importKey(String name, JsonWebKey keyMaterial)
Imports an externally createdkeyand stores it in the key vault. The import key operation may be used to import anykey typeinto Azure Key Vault. If akeywith the provided name already exists, Azure Key Vault creates a new version of thekey. This operation requires thekeys/importpermission.Code Samples
Imports a new
keyinto key vault. Subscribes to the call asynchronously and prints out the newlyimported keydetails when a response has been received.keyAsyncClient.importKey("keyName", jsonWebKeyToImport) .subscribe(keyVaultKey -> System.out.printf("Imported key with name: %s and id: %s%n", keyVaultKey.getName(), keyVaultKey.getId()));- Parameters:
name- The name for the imported key.keyMaterial- The Json web key being imported.- Returns:
- A
Monocontaining aResponsewhosevaluecontains theimported key. - Throws:
com.azure.core.exception.HttpResponseException- Ifnameis an empty string.
-
importKey
public Mono<KeyVaultKey> importKey(ImportKeyOptions importKeyOptions)
Imports an externally createdkeyand stores it in the key vault. The import key operation may be used to import anykey typeinto Azure Key Vault. If akeywith the provided name already exists, Azure Key Vault creates a new version of thekey. This operation requires thekeys/importpermission.ImportKeyOptionsis required and its fieldsnameandkey materialcannot benull. TheexpiresandnotBeforevalues inkeyImportOptionsare optional. If not specified, no values are set for the fields. Theenabledfield is set totrueand thehsmfield is set tofalseby Azure Key Vault, if they are not specified.Code Samples
Imports a new
keyinto key vault. Subscribes to the call asynchronously and prints out the newlyimported keydetails when a response has been received.ImportKeyOptions options = new ImportKeyOptions("keyName", jsonWebKeyToImport) .setHardwareProtected(false); keyAsyncClient.importKey(options).subscribe(keyVaultKey -> System.out.printf("Imported key with name: %s and id: %s%n", keyVaultKey.getName(), keyVaultKey.getId()));- Parameters:
importKeyOptions- Theoptions objectcontaining information about theJsonWebKeybeing imported.- Returns:
- A
Monocontaining theimported key. - Throws:
com.azure.core.exception.HttpResponseException- IfKeyProperties.getName()is an empty string.NullPointerException- IfimportKeyOptionsisnull.
-
importKeyWithResponse
public Mono<com.azure.core.http.rest.Response<KeyVaultKey>> importKeyWithResponse(ImportKeyOptions importKeyOptions)
Imports an externally createdkeyand stores it in the key vault. The import key operation may be used to import anykey typeinto Azure Key Vault. If akeywith the provided name already exists, Azure Key Vault creates a new version of thekey. This operation requires thekeys/importpermission.ImportKeyOptionsis required and its fieldsnameandkey materialcannot benull. TheexpiresandnotBeforevalues inkeyImportOptionsare optional. If not specified, no values are set for the fields. Theenabledfield is set totrueand thehsmfield is set tofalseby Azure Key Vault, if they are not specified.Code Samples
Imports a new
keyinto key vault. Subscribes to the call asynchronously and prints out the newlyimported keydetails when a response has been received.ImportKeyOptions importKeyOptions = new ImportKeyOptions("keyName", jsonWebKeyToImport) .setHardwareProtected(false); keyAsyncClient.importKeyWithResponse(importKeyOptions).subscribe(response -> System.out.printf("Imported key with name: %s and id: %s%n", response.getValue().getName(), response.getValue().getId()));- Parameters:
importKeyOptions- Theoptions objectcontaining information about theJsonWebKeybeing imported.- Returns:
- A
Monocontaining aResponsewhosevaluecontains theimported key. - Throws:
com.azure.core.exception.HttpResponseException- IfKeyProperties.getName()is an empty string.NullPointerException- IfimportKeyOptionsisnull.
-
getKey
public Mono<KeyVaultKey> getKey(String name, String version)
Gets the public part of the specifiedkeyand key version. The get key operation is applicable to allkey typesand it requires thekeys/getpermission.Code Samples
Gets a specific version of the
keyin the key vault. Subscribes to the call asynchronously and prints out theretrieved keydetails when a response has been received.String keyVersion = "6A385B124DEF4096AF1361A85B16C204"; keyAsyncClient.getKey("keyName", keyVersion) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(key -> System.out.printf("Created key with name: %s and: id %s%n", key.getName(), key.getId()));- Parameters:
name- The name of thekey, cannot benull.version- The version of the key to retrieve. If this is an empty String or null, this call is equivalent to callinggetKey(String), with the latest version being retrieved.- Returns:
- A
Monocontaining the requestedkey. The content of the key isnullif bothnameandversionarenullor empty. - Throws:
com.azure.core.exception.HttpResponseException- If a validnameand a non null/emptyversionis specified.com.azure.core.exception.ResourceNotFoundException- When akeywith the providednamedoesn't exist in the key vault or an empty/nullnameand a non-null/emptyversionis provided.
-
getKeyWithResponse
public Mono<com.azure.core.http.rest.Response<KeyVaultKey>> getKeyWithResponse(String name, String version)
Gets the public part of the specifiedkeyand key version. The get key operation is applicable to allkey typesand it requires thekeys/getpermission.Code Samples
Gets a specific version of the
keyin the key vault. Subscribes to the call asynchronously and prints out theretrieved keydetails when a response has been received.String keyVersion = "6A385B124DEF4096AF1361A85B16C204"; keyAsyncClient.getKeyWithResponse("keyName", keyVersion) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(getKeyResponse -> System.out.printf("Created key with name: %s and: id %s%n", getKeyResponse.getValue().getName(), getKeyResponse.getValue().getId()));- Parameters:
name- The name of thekey, cannot benull.version- The version of the key to retrieve. If this is an empty String or null, this call is equivalent to callinggetKey(String), with the latest version being retrieved.- Returns:
- A
Monocontaining aResponsewhosevaluecontains the requestedkey. The content of the key isnullif bothnameandversionarenullor empty. - Throws:
com.azure.core.exception.HttpResponseException- If a validnameand a non-null/emptyversionis specified.com.azure.core.exception.ResourceNotFoundException- When akeywith the providednamedoesn't exist in the key vault or an empty/nullnameand a non-null/emptyversionis provided.
-
getKey
public Mono<KeyVaultKey> getKey(String name)
Gets the public part of the specifiedkeyand key version. The get key operation is applicable to allkey typesand it requires thekeys/getpermission.Code Samples
Gets a specific version of the
keyin the key vault. Subscribes to the call asynchronously and prints out theretrieved keydetails when a response has been received.keyAsyncClient.getKey("keyName") .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(key -> System.out.printf("Created key with name: %s and: id %s%n", key.getName(), key.getId()));- Parameters:
name- The name of thekey, cannot benull.- Returns:
- A
Monocontaining the requestedkey. The content of the key isnullifnameisnullor empty. - Throws:
com.azure.core.exception.HttpResponseException- If a validnameand a non-null/emptyversionis specified.com.azure.core.exception.ResourceNotFoundException- When akeywith the providednamedoesn't exist in the key vault or an empty/nullnameand a non-null/emptyversionis provided.
-
updateKeyPropertiesWithResponse
public Mono<com.azure.core.http.rest.Response<KeyVaultKey>> updateKeyPropertiesWithResponse(KeyProperties keyProperties, KeyOperation... keyOperations)
Updates theattributesandkey operationsassociated with the specifiedkey, but not the cryptographic key material of the specifiedkeyin the key vault. The update operation changes specifiedattributesof an existing storedkeyandattributesthat are not specified in the request are left unchanged. The cryptographic key material of akeyitself cannot be changed. This operation requires thekeys/setpermission.Code Samples
Gets latest version of the
key, changes its notBefore time and then updates it in the Azure Key Vault. Subscribes to the call asynchronously and prints out thereturned keydetails when a response has been received.keyAsyncClient.getKey("keyName") .subscribe(getKeyResponse -> { //Update the not before time of the key. getKeyResponse.getProperties().setNotBefore(OffsetDateTime.now().plusDays(50)); keyAsyncClient.updateKeyPropertiesWithResponse(getKeyResponse.getProperties(), KeyOperation.ENCRYPT, KeyOperation.DECRYPT) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(updateKeyResponse -> System.out.printf("Updated key's \"not before time\": %s%n", updateKeyResponse.getValue().getProperties().getNotBefore().toString())); });- Parameters:
keyProperties- Thekey propertiesobject with updated properties.keyOperations- The updatedkey operationsto associate with the key.- Returns:
- A
Monocontaining aResponsewhosevaluecontains theupdated key. - Throws:
com.azure.core.exception.HttpResponseException- Ifnameorversionis an empty string.NullPointerException- Ifkeyisnull.com.azure.core.exception.ResourceNotFoundException- When a key withnameandversiondoesn't exist in the key vault.
-
updateKeyProperties
public Mono<KeyVaultKey> updateKeyProperties(KeyProperties keyProperties, KeyOperation... keyOperations)
Updates theattributesandkey operationsassociated with the specifiedkey, but not the cryptographic key material of the specifiedkeyin the key vault. The update operation changes specifiedattributesof an existing storedkeyandattributesthat are not specified in the request are left unchanged. The cryptographic key material of akeyitself cannot be changed. This operation requires thekeys/setpermission.Code Samples
Gets latest version of the
key, changes its notBefore time and then updates it in the Azure Key Vault. Subscribes to the call asynchronously and prints out thereturned keydetails when a response has been received.keyAsyncClient.getKey("keyName") .subscribe(key -> { //Update the not before time of the key. key.getProperties().setNotBefore(OffsetDateTime.now().plusDays(50)); keyAsyncClient.updateKeyProperties(key.getProperties(), KeyOperation.ENCRYPT, KeyOperation.DECRYPT) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(updatedKey -> System.out.printf("Updated key's \"not before time\": %s%n", updatedKey.getProperties().getNotBefore().toString())); });- Parameters:
keyProperties- Thekey propertiesobject with updated properties.keyOperations- The updatedkey operationsto associate with the key.- Returns:
- A
Monocontaining theupdated key. - Throws:
com.azure.core.exception.HttpResponseException- Ifnameorversionis an empty string.NullPointerException- Ifkeyisnull.com.azure.core.exception.ResourceNotFoundException- When a key withnameandversiondoesn't exist in the key vault.
-
beginDeleteKey
public com.azure.core.util.polling.PollerFlux<DeletedKey,Void> beginDeleteKey(String name)
Deletes akeyof any type from the key vault. If soft-delete is enabled on the key vault then thekeyis placed in the deleted state and requires to be purged for permanent deletion else thekeyis permanently deleted. The delete operation applies to anykeystored in Azure Key Vault but it cannot be applied to an individual version of akey. This operation removes the cryptographic material associated with thekey, which means thekeyis not usable forSign/Verify,Wrap/UnwraporEncrypt/Decryptoperations. This operation requires thekeys/deletepermission.Code Samples
Deletes the
keyin the Azure Key Vault. Subscribes to the call asynchronously and prints out thedeleted keydetails when a response has been received.keyAsyncClient.beginDeleteKey("keyName") .subscribe(pollResponse -> { System.out.printf("Deletion status: %s%n", pollResponse.getStatus()); System.out.printf("Key name: %s%n", pollResponse.getValue().getName()); System.out.printf("Key delete date: %s%n", pollResponse.getValue().getDeletedOn()); });- Parameters:
name- The name of thekeyto be deleted.- Returns:
- A
PollerFluxto poll on thedeleted keystatus. - Throws:
com.azure.core.exception.HttpResponseException- When a key withnameis an empty string.com.azure.core.exception.ResourceNotFoundException- When a key withnamedoesn't exist in the key vault.
-
getDeletedKey
public Mono<DeletedKey> getDeletedKey(String name)
Gets the public part of adeleted key. The get deleted Key operation is applicable for soft-delete enabled vaults. This operation requires thekeys/getpermission.Code Samples
Gets the
deleted keyfrom the key vault enabled for soft-delete. Subscribes to the call asynchronously and prints out thedeleted keydetails when a response has been received.keyAsyncClient.getDeletedKey("keyName") .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(deletedKey -> System.out.printf("Deleted key's recovery id:%s%n", deletedKey.getRecoveryId()));- Parameters:
name- The name of the deletedkey.- Returns:
- A
Monocontaining thedeleted key. - Throws:
com.azure.core.exception.HttpResponseException- When a key withnameis an empty string.com.azure.core.exception.ResourceNotFoundException- When a key withnamedoesn't exist in the key vault.
-
getDeletedKeyWithResponse
public Mono<com.azure.core.http.rest.Response<DeletedKey>> getDeletedKeyWithResponse(String name)
Gets the public part of adeleted key. The get deleted Key operation is applicable for soft-delete enabled vaults. This operation requires thekeys/getpermission.Code Samples
Gets the
deleted keyfrom the key vault enabled for soft-delete. Subscribes to the call asynchronously and prints out thedeleted keydetails when a response has been received.keyAsyncClient.getDeletedKeyWithResponse("keyName") .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(getDeletedKeyResponse -> System.out.printf("Deleted key's recovery id: %s%n", getDeletedKeyResponse.getValue().getRecoveryId()));- Parameters:
name- The name of the deletedkey.- Returns:
- A
Monocontaining aResponsewhosevaluecontains thedeleted key. - Throws:
com.azure.core.exception.HttpResponseException- When a key withnameis an empty string.com.azure.core.exception.ResourceNotFoundException- When a key withnamedoesn't exist in the key vault.
-
purgeDeletedKey
public Mono<Void> purgeDeletedKey(String name)
Permanently deletes the specifiedkeywithout the possibility of recovery. The purge deleted key operation is applicable for soft-delete enabled vaults. This operation requires thekeys/purgepermission.Code Samples
Purges the
deleted keyfrom the key vault enabled for soft-delete. Subscribes to the call asynchronously and prints out the status code from the server response when a response has been received.keyAsyncClient.purgeDeletedKey("deletedKeyName") .subscribe(ignored -> System.out.println("Successfully purged deleted key"));- Parameters:
name- The name of thedeleted key.- Returns:
- An empty
Mono. - Throws:
com.azure.core.exception.HttpResponseException- When a key withnameis an empty string.com.azure.core.exception.ResourceNotFoundException- When a key withnamedoesn't exist in the key vault.
-
purgeDeletedKeyWithResponse
public Mono<com.azure.core.http.rest.Response<Void>> purgeDeletedKeyWithResponse(String name)
Permanently deletes the specifiedkeywithout the possibility of recovery. The purge deleted key operation is applicable for soft-delete enabled vaults. This operation requires thekeys/purgepermission.Code Samples
Purges the
deleted keyfrom the key vault enabled for soft-delete. Subscribes to the call asynchronously and prints out the status code from the server response when a response has been received.keyAsyncClient.purgeDeletedKeyWithResponse("deletedKeyName") .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(purgeDeletedKeyResponse -> System.out.printf("Purge response status code: %d%n", purgeDeletedKeyResponse.getStatusCode()));- Parameters:
name- The name of thedeleted key.- Returns:
- A
Monocontaining a Response containing status code and HTTP headers. - Throws:
com.azure.core.exception.HttpResponseException- When a key withnameis an empty string.com.azure.core.exception.ResourceNotFoundException- When a key withnamedoesn't exist in the key vault.
-
beginRecoverDeletedKey
public com.azure.core.util.polling.PollerFlux<KeyVaultKey,Void> beginRecoverDeletedKey(String name)
Recovers thedeleted keyin the key vault to its latest version and can only be performed on a soft-delete enabled vault. An attempt to recover annon-deleted keywill return an error. Consider this the inverse of the delete operation on soft-delete enabled vaults. This operation requires thekeys/recoverpermission.Code Samples
Recovers the
deleted keyfrom the key vault enabled for soft-delete. Subscribes to the call asynchronously and prints out the recovered key details when a response has been received.keyAsyncClient.beginRecoverDeletedKey("deletedKeyName") .subscribe(pollResponse -> { System.out.printf("Recovery status: %s%n", pollResponse.getStatus()); System.out.printf("Key name: %s%n", pollResponse.getValue().getName()); System.out.printf("Key type: %s%n", pollResponse.getValue().getKeyType()); });- Parameters:
name- The name of thedeleted keyto be recovered.- Returns:
- A
PollerFluxto poll on therecovered keystatus. - Throws:
com.azure.core.exception.HttpResponseException- When a key withnameis an empty string.com.azure.core.exception.ResourceNotFoundException- When a key withnamedoesn't exist in the key vault.
-
backupKey
public Mono<byte[]> backupKey(String name)
Requests a backup of the specifiedkeybe downloaded to the client. The key backup operation exports akeyfrom Azure Key Vault in a protected form. Note that this operation does not return key material in a form that can be used outside the Azure Key Vault system, the returned key material is either protected to a Azure Key Vault HSM or to Azure Key Vault itself. The intent of this operation is to allow a client to generate akeyin one Azure Key Vault instance, backup thekey, and then restore it into another Azure Key Vault instance. The backup operation may be used to export, in protected form, anykey typefrom Azure Key Vault. Individual versions of akeycannot be backed up.Backup/Restorecan be performed within geographical boundaries only; meaning that a backup from one geographical area cannot be restored to another geographical area. For example, a backup from the US geographical area cannot be restored in an EU geographical area. This operation requires thekey/backuppermission.Code Samples
Backs up the
keyfrom the key vault. Subscribes to the call asynchronously and prints out the length of the key's backup byte array returned in the response.keyAsyncClient.backupKey("keyName") .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(bytes -> System.out.printf("Key backup byte array length: %s%n", bytes.length));
-
backupKeyWithResponse
public Mono<com.azure.core.http.rest.Response<byte[]>> backupKeyWithResponse(String name)
Requests a backup of the specifiedkeybe downloaded to the client. The key backup operation exports akeyfrom Azure Key Vault in a protected form. Note that this operation does not return key material in a form that can be used outside the Azure Key Vault system, the returned key material is either protected to a Azure Key Vault HSM or to Azure Key Vault itself. The intent of this operation is to allow a client to generate akeyin one Azure Key Vault instance, backup thekey, and then restore it into another Azure Key Vault instance. The backup operation may be used to export, in protected form, anykey typefrom Azure Key Vault. Individual versions of akeycannot be backed up.Backup/Restorecan be performed within geographical boundaries only; meaning that a backup from one geographical area cannot be restored to another geographical area. For example, a backup from the US geographical area cannot be restored in an EU geographical area. This operation requires thekey/backuppermission.Code Samples
Backs up the
keyfrom the key vault. Subscribes to the call asynchronously and prints out the length of the key's backup byte array returned in the response.keyAsyncClient.backupKeyWithResponse("keyName") .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(backupKeyResponse -> System.out.printf("Key backup byte array length: %s%n", backupKeyResponse.getValue().length));- Parameters:
name- The name of thekey.- Returns:
- A
Monocontaining aResponsewhosevaluecontains the backed up key blob. - Throws:
com.azure.core.exception.ResourceNotFoundException- When a key withnamedoesn't exist in the key vault.com.azure.core.exception.HttpResponseException- When a key withnameis an empty string.
-
restoreKeyBackup
public Mono<KeyVaultKey> restoreKeyBackup(byte[] backup)
Restores a backed upkeyto a vault. Imports a previously backed upkeyinto Azure Key Vault, restoring thekey, its key identifier, attributes and access control policies. The restore operation may be used to import a previously backed upkey. Individual versions of akeycannot be restored. Thekeyis restored in its entirety with the same key name as it had when it was backed up. If the key name is not available in the target key vault, the restore operation will be rejected. While the key name is retained during restore, the final key identifier will change if thekeyis restored to a different vault. Restore will restore all versions and preserve version identifiers. The restore operation is subject to security constraints: The target key vault must be owned by the same Microsoft Azure Subscription as the source key vault. The user must have therestorepermission in the target key vault. This operation requires thekeys/restorepermission.Code Samples
Restores the
//Pass the Key Backup Byte array to the restore operation.keyin the key vault from its backup. Subscribes to the call asynchronously and prints out the restored key details when a response has been received.keyAsyncClient.restoreKeyBackup(keyBackupByteArray) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(restoreKeyResponse -> System.out.printf("Restored key with name: %s and: id %s%n", restoreKeyResponse.getName(), restoreKeyResponse.getId()));- Parameters:
backup- The backup blob associated with thekey.- Returns:
- A
Monocontaining therestored key. - Throws:
com.azure.core.exception.ResourceModifiedException- Whenbackupblob is malformed.
-
restoreKeyBackupWithResponse
public Mono<com.azure.core.http.rest.Response<KeyVaultKey>> restoreKeyBackupWithResponse(byte[] backup)
Restores a backed upkeyto a vault. Imports a previously backed upkeyinto Azure Key Vault, restoring thekey, its key identifier, attributes and access control policies. The restore operation may be used to import a previously backed upkey. Individual versions of akeycannot be restored. Thekeyis restored in its entirety with the same key name as it had when it was backed up. If the key name is not available in the target key vault, the restore operation will be rejected. While the key name is retained during restore, the final key identifier will change if thekeyis restored to a different vault. Restore will restore all versions and preserve version identifiers. The restore operation is subject to security constraints: The target key vault must be owned by the same Microsoft Azure Subscription as the source key vault. The user must have therestorepermission in the target key vault. This operation requires thekeys/restorepermission.Code Samples
Restores the
//Pass the Key Backup Byte array to the restore operation.keyin the key vault from its backup. Subscribes to the call asynchronously and prints out the restored key details when a response has been received.keyAsyncClient.restoreKeyBackupWithResponse(keyBackupByteArray) .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(restoreKeyBackupResponse -> System.out.printf("Restored key with name: %s and: id %s%n", restoreKeyBackupResponse.getValue().getName(), restoreKeyBackupResponse.getValue().getId()));- Parameters:
backup- The backup blob associated with thekey.- Returns:
- A
Monocontaining aResponsewhosevaluecontains therestored key. - Throws:
com.azure.core.exception.ResourceModifiedException- Whenbackupblob is malformed.
-
listPropertiesOfKeys
public com.azure.core.http.rest.PagedFlux<KeyProperties> listPropertiesOfKeys()
Listkeysin the key vault. Retrieves a list of thekeysin the key vault asJsonWebKeystructures that contain the public part of a storedkey. The list operation is applicable to allkey typesand the individualkeyresponse in the list is represented byKeyPropertiesas only the key identifier, attributes and tags are provided in the response. The key material and individual key versions are not listed in the response. This operation requires thekeys/listpermission.Code Samples
It is possible to get
full keyswith key material from this information. Convert theFluxcontainingkey propertiestoFluxcontainingkeyusinggetKey(String, String)withinFlux.flatMap(Function).keyAsyncClient.listPropertiesOfKeys() .contextWrite(Context.of("key1", "value1", "key2", "value2")) .flatMap(keyProperties -> keyAsyncClient.getKey(keyProperties.getName(), keyProperties.getVersion())) .subscribe(key -> System.out.printf("Retrieved key with name: %s and type: %s%n", key.getName(), key.getKeyType()));- Returns:
- A
PagedFluxcontainingkeyof all the keys in the vault.
-
listDeletedKeys
public com.azure.core.http.rest.PagedFlux<DeletedKey> listDeletedKeys()
Listsdeleted keysof the key vault. Thedeleted keysare retrieved asJsonWebKeystructures that contain the public part of adeleted key. The get deleted keys operation is applicable for vaults enabled for soft-delete. This operation requires thekeys/listpermission.Code Samples
Lists the
deleted keysin the key vault. Subscribes to the call asynchronously and prints out the recovery id of eachdeleted keywhen a response has been received.keyAsyncClient.listDeletedKeys() .contextWrite(Context.of("key1", "value1", "key2", "value2")) .subscribe(deletedKey -> System.out.printf("Deleted key's recovery id:%s%n", deletedKey.getRecoveryId()));- Returns:
- A
PagedFluxcontaining all of thedeleted keysin the vault.
-
listPropertiesOfKeyVersions
public com.azure.core.http.rest.PagedFlux<KeyProperties> listPropertiesOfKeyVersions(String name)
List all versions of the specifiedkeys. The individual key response in the flux is represented byKeyPropertiesas only the key identifier, attributes and tags are provided in the response. The key material values are not provided in the response. This operation requires thekeys/listpermission.Code Samples
It is possible to get the keys with key material of all the versions from this information. Convert the
Fluxcontainingkey propertiestoFluxcontainingkeyusinggetKey(String, String)withinFlux.flatMap(Function).keyAsyncClient.listPropertiesOfKeyVersions("keyName") .contextWrite(Context.of("key1", "value1", "key2", "value2")) .flatMap(keyProperties -> keyAsyncClient.getKey(keyProperties.getName(), keyProperties.getVersion())) .subscribe(key -> System.out.printf("Retrieved key version: %s with name: %s and type: %s%n", key.getProperties().getVersion(), key.getName(), key.getKeyType()));- Parameters:
name- The name of thekey.- Returns:
- A
PagedFluxcontainingKeyPropertiesof all the versions of the specifiedkeysin the vault.Fluxis empty if key withnamedoes not exist in the key vault. - Throws:
com.azure.core.exception.ResourceNotFoundException- When a given keynameisnullor an empty string.
-
-