B
Beacon Globe News

Class SecretClient | Azure SDK for .NET

Author

Christopher Ramos

Published Feb 17, 2026

The SecretClient provides synchronous and asynchronous methods to manage KeyVaultSecret in the Azure Key Vault. The client supports creating, retrieving, updating, deleting, purging, backing up, restoring, and listing KeyVaultSecret. The client also supports listing DeletedSecret for a soft-delete enabled Azure Key Vault.

Inheritance

System.Object

SecretClient

Namespace: System.Dynamic.ExpandoObject
Assembly: Azure.Security.KeyVault.Secrets.dll
Syntax
public class SecretClient

Constructors

SecretClient()

Initializes a new instance of the SecretClient class for mocking.

Declaration
protected SecretClient ();

SecretClient(Uri, TokenCredential)

Initializes a new instance of the SecretClient class for the specified vault.

Declaration
public SecretClient (Uri vaultUri, Azure.Core.TokenCredential credential);
Parameters
System.Uri vaultUri

A System.Uri to the vault on which the client operates. Appears as "DNS Name" in the Azure portal. If you have a secret System.Uri, use KeyVaultSecretIdentifier to parse the VaultUri and other information.

Azure.Core.TokenCredential credential

A Azure.Core.TokenCredential used to authenticate requests to the vault, such as DefaultAzureCredential.

Exceptions
System.ArgumentNullException

vaultUri or credential is null.

SecretClient(Uri, TokenCredential, SecretClientOptions)

Initializes a new instance of the SecretClient class for the specified vault.

Declaration
public SecretClient (Uri vaultUri, Azure.Core.TokenCredential credential, Azure.Security.KeyVault.Secrets.SecretClientOptions options);
Parameters
System.Uri vaultUri

A System.Uri to the vault on which the client operates. Appears as "DNS Name" in the Azure portal. If you have a secret System.Uri, use KeyVaultSecretIdentifier to parse the VaultUri and other information.

Azure.Core.TokenCredential credential

A Azure.Core.TokenCredential used to authenticate requests to the vault, such as DefaultAzureCredential.

SecretClientOptions options

SecretClientOptions that allow to configure the management of the request sent to Key Vault.

Exceptions
System.ArgumentNullException

vaultUri or credential is null.

Properties

VaultUri

Gets the System.Uri of the vault used to create this instance of the SecretClient.

Declaration
public virtual Uri VaultUri { get; }
Property Value
System.Uri

Methods

BackupSecret(String, CancellationToken)

Backs up the specified secret.

Declaration
public virtual Azure.Response<byte[]> BackupSecret (string name, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Azure.Response<System.Byte[]>
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

BackupSecretAsync(String, CancellationToken)

Backs up the specified secret.

Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<Azure.Response<byte[]>> BackupSecretAsync (string name, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
System.Threading.Tasks.Task<Azure.Response<System.Byte[]>>
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

GetDeletedSecret(String, CancellationToken)

Gets the specified deleted secret.

Declaration
public virtual Azure.Response<Azure.Security.KeyVault.Secrets.DeletedSecret> GetDeletedSecret (string name, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

GetDeletedSecretAsync(String, CancellationToken)

Gets the specified deleted secret.

Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Security.KeyVault.Secrets.DeletedSecret>> GetDeletedSecretAsync (string name, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

GetDeletedSecrets(CancellationToken)

Lists deleted secrets for the specified vault.

Declaration
public virtual Azure.Pageable<Azure.Security.KeyVault.Secrets.DeletedSecret> GetDeletedSecrets (System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

GetDeletedSecretsAsync(CancellationToken)

Lists deleted secrets for the specified vault.

Declaration
public virtual Azure.AsyncPageable<Azure.Security.KeyVault.Secrets.DeletedSecret> GetDeletedSecretsAsync (System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

GetPropertiesOfSecrets(CancellationToken)

Declaration
public virtual Azure.Pageable<Azure.Security.KeyVault.Secrets.SecretProperties> GetPropertiesOfSecrets (System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

GetPropertiesOfSecretsAsync(CancellationToken)

Declaration
public virtual Azure.AsyncPageable<Azure.Security.KeyVault.Secrets.SecretProperties> GetPropertiesOfSecretsAsync (System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

GetPropertiesOfSecretVersions(String, CancellationToken)

Declaration
public virtual Azure.Pageable<Azure.Security.KeyVault.Secrets.SecretProperties> GetPropertiesOfSecretVersions (string name, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

GetPropertiesOfSecretVersionsAsync(String, CancellationToken)

Declaration
public virtual Azure.AsyncPageable<Azure.Security.KeyVault.Secrets.SecretProperties> GetPropertiesOfSecretVersionsAsync (string name, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

GetSecret(String, String, CancellationToken)

Get a specified secret from a given key vault.

Declaration
public virtual Azure.Response<Azure.Security.KeyVault.Secrets.KeyVaultSecret> GetSecret (string name, string version = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.String version

The version of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

GetSecretAsync(String, String, CancellationToken)

Get a specified secret from a given key vault.

Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Security.KeyVault.Secrets.KeyVaultSecret>> GetSecretAsync (string name, string version = null, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.String version

The version of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

PurgeDeletedSecret(String, CancellationToken)

Permanently deletes the specified secret.

Declaration
public virtual Azure.Response PurgeDeletedSecret (string name, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Azure.Response
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

PurgeDeletedSecretAsync(String, CancellationToken)

Permanently deletes the specified secret.

Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<Azure.Response> PurgeDeletedSecretAsync (string name, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
System.Threading.Tasks.Task<Azure.Response>
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

RestoreSecretBackup(Byte[], CancellationToken)

Restores a backed up secret to a vault.

Declaration
public virtual Azure.Response<Azure.Security.KeyVault.Secrets.SecretProperties> RestoreSecretBackup (byte[] backup, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Byte[] backup

The backup blob associated with a secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentNullException

backup is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

RestoreSecretBackupAsync(Byte[], CancellationToken)

Restores a backed up secret to a vault.

Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Security.KeyVault.Secrets.SecretProperties>> RestoreSecretBackupAsync (byte[] backup, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Byte[] backup

The backup blob associated with a secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentNullException

backup is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

SetSecret(KeyVaultSecret, CancellationToken)

Sets a secret in a specified key vault.

Declaration
public virtual Azure.Response<Azure.Security.KeyVault.Secrets.KeyVaultSecret> SetSecret (Azure.Security.KeyVault.Secrets.KeyVaultSecret secret, System.Threading.CancellationToken cancellationToken = null);
Parameters
KeyVaultSecret secret

The Secret object containing information about the secret and its properties. The properties secret.Name and secret.Value must be non null.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentNullException

secret is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

SetSecret(String, String, CancellationToken)

Sets a secret in a specified key vault.

Declaration
public virtual Azure.Response<Azure.Security.KeyVault.Secrets.KeyVaultSecret> SetSecret (string name, string value, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.String value

The value of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

SetSecretAsync(KeyVaultSecret, CancellationToken)

Sets a secret in a specified key vault.

Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Security.KeyVault.Secrets.KeyVaultSecret>> SetSecretAsync (Azure.Security.KeyVault.Secrets.KeyVaultSecret secret, System.Threading.CancellationToken cancellationToken = null);
Parameters
KeyVaultSecret secret

The Secret object containing information about the secret and its properties. The properties secret.Name and secret.Value must be non null.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentNullException

secret is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

SetSecretAsync(String, String, CancellationToken)

Sets a secret in a specified key vault.

Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Security.KeyVault.Secrets.KeyVaultSecret>> SetSecretAsync (string name, string value, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret. It must not be null.

System.String value

The value of the secret. It must not be null.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

StartDeleteSecret(String, CancellationToken)

Deletes a secret from a specified key vault.

Declaration
public virtual Azure.Security.KeyVault.Secrets.DeleteSecretOperation StartDeleteSecret (string name, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

StartDeleteSecretAsync(String, CancellationToken)

Deletes a secret from a specified key vault.

Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<Azure.Security.KeyVault.Secrets.DeleteSecretOperation> StartDeleteSecretAsync (string name, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
System.Threading.Tasks.Task<DeleteSecretOperation>

A DeleteSecretOperation to wait on this long-running operation. If the Key Vault is soft delete-enabled, you only need to wait for the operation to complete if you need to recover or purge the secret; otherwise, the secret is deleted automatically on the ScheduledPurgeDate.

Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

StartRecoverDeletedSecret(String, CancellationToken)

Recovers the deleted secret to the latest version.

Declaration
public virtual Azure.Security.KeyVault.Secrets.RecoverDeletedSecretOperation StartRecoverDeletedSecret (string name, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

StartRecoverDeletedSecretAsync(String, CancellationToken)

Recovers the deleted secret to the latest version.

Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<Azure.Security.KeyVault.Secrets.RecoverDeletedSecretOperation> StartRecoverDeletedSecretAsync (string name, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String name

The name of the secret.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentException

name is an empty string.

System.ArgumentNullException

name is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

UpdateSecretProperties(SecretProperties, CancellationToken)

Updates the attributes associated with a specified secret.

Declaration
public virtual Azure.Response<Azure.Security.KeyVault.Secrets.SecretProperties> UpdateSecretProperties (Azure.Security.KeyVault.Secrets.SecretProperties properties, System.Threading.CancellationToken cancellationToken = null);
Parameters
SecretProperties properties

The secret object with updated properties.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentNullException

properties or Version is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.

UpdateSecretPropertiesAsync(SecretProperties, CancellationToken)

Updates the attributes associated with a specified secret.

Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Security.KeyVault.Secrets.SecretProperties>> UpdateSecretPropertiesAsync (Azure.Security.KeyVault.Secrets.SecretProperties properties, System.Threading.CancellationToken cancellationToken = null);
Parameters
SecretProperties properties

The secret object with updated properties.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Exceptions
System.ArgumentNullException

properties or Version is null.

Azure.RequestFailedException

The server returned an error. See System.Exception.Message for details returned from the server.