constructorVersionedAesGcmSecretProtector
public VersionedAesGcmSecretProtector(IOptions<VersionedSecretProtectorOptions> options)
Initializes a new instance of the `VersionedAesGcmSecretProtector` class from `IOptions<TOptions>`.
- options: IOptions<VersionedSecretProtectorOptions>
- The configured `VersionedSecretProtectorOptions` wrapper.
constructorVersionedAesGcmSecretProtector
public VersionedAesGcmSecretProtector(VersionedSecretProtectorOptions options)
Initializes a new instance of the `VersionedAesGcmSecretProtector` class.
- options: VersionedSecretProtectorOptions
- The configured `VersionedSecretProtectorOptions`.
methodDispose
public void Dispose()
Scrubs all master encryption key material from memory.
methodProtect
public Result<VersionedSecretEnvelope> Protect(ReadOnlySpan<byte> plaintext, string purpose, AuthenticatedContext associatedData)
Encrypts and authenticates a plaintext byte span into a versioned `v1.<base64url>` envelope bound to external AAD.
- plaintext: ReadOnlySpan<byte>
- The plaintext secret bytes to protect.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: AuthenticatedContext
- The external authenticated context (AAD) bound to the authentication tag.
Returns: A `Result<T>` containing the `VersionedSecretEnvelope` on success.
methodProtect
public Result<VersionedSecretEnvelope> Protect(ReadOnlySpan<byte> plaintext, string purpose, ReadOnlySpan<byte> associatedData)
Encrypts and authenticates a plaintext byte span into a versioned `v1.<base64url>` envelope bound to external AAD.
- plaintext: ReadOnlySpan<byte>
- The plaintext secret bytes to protect.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: ReadOnlySpan<byte>
- The external authenticated context (AAD) bound to the authentication tag.
Returns: A `Result<T>` containing the `VersionedSecretEnvelope` on success.
methodProtect
public Result<VersionedSecretEnvelope> Protect(ReadOnlySpan<byte> plaintext, string purpose, string? associatedDataContext)
Encrypts and authenticates a plaintext byte span into a versioned `v1.<base64url>` envelope bound to external AAD.
- plaintext: ReadOnlySpan<byte>
- The plaintext secret bytes to protect.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedDataContext: string?
Returns: A `Result<T>` containing the `VersionedSecretEnvelope` on success.
methodProtectString
public Result<VersionedSecretEnvelope> ProtectString(string plaintext, string purpose, AuthenticatedContext associatedData)
Encrypts and authenticates a UTF-8 plaintext secret string into a versioned `v1.<base64url>` envelope, scrubbing intermediate UTF-8 plaintext bytes from memory before returning.
- plaintext: string
- The non-empty plaintext string to protect.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: AuthenticatedContext
- The external authenticated context (AAD) bound to the authentication tag.
Returns: A `Result<T>` containing the `VersionedSecretEnvelope` on success.
methodProtectString
public Result<VersionedSecretEnvelope> ProtectString(string plaintext, string purpose, ReadOnlySpan<byte> associatedData)
Encrypts and authenticates a UTF-8 plaintext secret string into a versioned `v1.<base64url>` envelope, scrubbing intermediate UTF-8 plaintext bytes from memory before returning.
- plaintext: string
- The non-empty plaintext string to protect.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: ReadOnlySpan<byte>
- The external authenticated context (AAD) bound to the authentication tag.
Returns: A `Result<T>` containing the `VersionedSecretEnvelope` on success.
methodProtectString
public Result<VersionedSecretEnvelope> ProtectString(string plaintext, string purpose, string? associatedDataContext)
Encrypts and authenticates a UTF-8 plaintext secret string into a versioned `v1.<base64url>` envelope, scrubbing intermediate UTF-8 plaintext bytes from memory before returning.
- plaintext: string
- The non-empty plaintext string to protect.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedDataContext: string?
Returns: A `Result<T>` containing the `VersionedSecretEnvelope` on success.
methodProtectStringToBytes
public Result<byte[]> ProtectStringToBytes(string plaintext, string purpose, AuthenticatedContext associatedData)
Encrypts and authenticates a UTF-8 plaintext string into a compact binary versioned AEAD payload, scrubbing intermediate plaintext bytes.
- plaintext: string
- The non-empty plaintext string to protect.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: AuthenticatedContext
- The external authenticated context (AAD) bound to the authentication tag.
Returns: A `Result<T>` containing the binary versioned AEAD payload on success.
methodProtectStringToBytes
public Result<byte[]> ProtectStringToBytes(string plaintext, string purpose, ReadOnlySpan<byte> associatedData)
Encrypts and authenticates a UTF-8 plaintext string into a compact binary versioned AEAD payload, scrubbing intermediate plaintext bytes.
- plaintext: string
- The non-empty plaintext string to protect.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: ReadOnlySpan<byte>
- The external authenticated context (AAD) bound to the authentication tag.
Returns: A `Result<T>` containing the binary versioned AEAD payload on success.
methodProtectStringToBytes
public Result<byte[]> ProtectStringToBytes(string plaintext, string purpose, string? associatedDataContext)
Encrypts and authenticates a UTF-8 plaintext string into a compact binary versioned AEAD payload, scrubbing intermediate plaintext bytes.
- plaintext: string
- The non-empty plaintext string to protect.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedDataContext: string?
Returns: A `Result<T>` containing the binary versioned AEAD payload on success.
methodProtectToBytes
public Result<byte[]> ProtectToBytes(ReadOnlySpan<byte> plaintext, string purpose, AuthenticatedContext associatedData)
Encrypts and authenticates a plaintext byte span into a compact binary versioned AEAD payload.
- plaintext: ReadOnlySpan<byte>
- The plaintext secret bytes to protect.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: AuthenticatedContext
- The external authenticated context (AAD) bound to the authentication tag.
Returns: A `Result<T>` containing the binary versioned AEAD payload on success.
methodProtectToBytes
public Result<byte[]> ProtectToBytes(ReadOnlySpan<byte> plaintext, string purpose, ReadOnlySpan<byte> associatedData)
Encrypts and authenticates a plaintext byte span into a compact binary versioned AEAD payload.
- plaintext: ReadOnlySpan<byte>
- The plaintext secret bytes to protect.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: ReadOnlySpan<byte>
- The external authenticated context (AAD) bound to the authentication tag.
Returns: A `Result<T>` containing the binary versioned AEAD payload on success.
methodProtectToBytes
public Result<byte[]> ProtectToBytes(ReadOnlySpan<byte> plaintext, string purpose, string? associatedDataContext)
Encrypts and authenticates a plaintext byte span into a compact binary versioned AEAD payload.
- plaintext: ReadOnlySpan<byte>
- The plaintext secret bytes to protect.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedDataContext: string?
Returns: A `Result<T>` containing the binary versioned AEAD payload on success.
methodUnprotect
public Result<byte[]> Unprotect(string ciphertextEnvelope, string purpose, AuthenticatedContext associatedData, int expectedKeyVersion = 0)
Decrypts and authenticates a `v1.<base64url>` envelope using the reconstructed external AAD and optional expected key version.
- ciphertextEnvelope: string
- The persisted `v1.<base64url>` envelope string.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: AuthenticatedContext
- The external authenticated context (AAD) to verify.
- expectedKeyVersion: int
- Optional expected key version (`> 0` enforces exact header match; `<= 0` accepts any loaded version in the key ring).
Returns: A `Result<T>` containing the decrypted plaintext byte array on success.
methodUnprotect
public Result<byte[]> Unprotect(string ciphertextEnvelope, string purpose, ReadOnlySpan<byte> associatedData, int expectedKeyVersion = 0)
Decrypts and authenticates a `v1.<base64url>` envelope using the reconstructed external AAD and optional expected key version.
- ciphertextEnvelope: string
- The persisted `v1.<base64url>` envelope string.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: ReadOnlySpan<byte>
- The external authenticated context (AAD) to verify.
- expectedKeyVersion: int
- Optional expected key version (`> 0` enforces exact header match; `<= 0` accepts any loaded version in the key ring).
Returns: A `Result<T>` containing the decrypted plaintext byte array on success.
methodUnprotect
public Result<byte[]> Unprotect(string ciphertextEnvelope, string purpose, string? associatedDataContext, int expectedKeyVersion = 0)
Decrypts and authenticates a `v1.<base64url>` envelope using the reconstructed external AAD and optional expected key version.
- ciphertextEnvelope: string
- The persisted `v1.<base64url>` envelope string.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedDataContext: string?
- expectedKeyVersion: int
- Optional expected key version (`> 0` enforces exact header match; `<= 0` accepts any loaded version in the key ring).
Returns: A `Result<T>` containing the decrypted plaintext byte array on success.
methodUnprotectFromBytes
public Result<byte[]> UnprotectFromBytes(ReadOnlySpan<byte> ciphertextPayload, string purpose, AuthenticatedContext associatedData, int expectedKeyVersion = 0)
Decrypts and authenticates a compact binary versioned AEAD payload using external `AuthenticatedContext` AAD.
- ciphertextPayload: ReadOnlySpan<byte>
- The binary versioned AEAD payload produced by `ProtectToBytes(ReadOnlySpan<byte>, string, AuthenticatedContext)`.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: AuthenticatedContext
- The external authenticated context (AAD) to verify.
- expectedKeyVersion: int
- Optional expected key version.
Returns: A `Result<T>` containing the decrypted plaintext byte array on success.
methodUnprotectFromBytes
public Result<byte[]> UnprotectFromBytes(ReadOnlySpan<byte> ciphertextPayload, string purpose, ReadOnlySpan<byte> associatedData, int expectedKeyVersion = 0)
Decrypts and authenticates a compact binary versioned AEAD payload using external `AuthenticatedContext` AAD.
- ciphertextPayload: ReadOnlySpan<byte>
- The binary versioned AEAD payload produced by `ProtectToBytes(ReadOnlySpan<byte>, string, AuthenticatedContext)`.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: ReadOnlySpan<byte>
- The external authenticated context (AAD) to verify.
- expectedKeyVersion: int
- Optional expected key version.
Returns: A `Result<T>` containing the decrypted plaintext byte array on success.
methodUnprotectFromBytes
public Result<byte[]> UnprotectFromBytes(ReadOnlySpan<byte> ciphertextPayload, string purpose, string? associatedDataContext, int expectedKeyVersion = 0)
Decrypts and authenticates a compact binary versioned AEAD payload using external `AuthenticatedContext` AAD.
- ciphertextPayload: ReadOnlySpan<byte>
- The binary versioned AEAD payload produced by `ProtectToBytes(ReadOnlySpan<byte>, string, AuthenticatedContext)`.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedDataContext: string?
- expectedKeyVersion: int
- Optional expected key version.
Returns: A `Result<T>` containing the decrypted plaintext byte array on success.
methodUnprotectString
public Result<string> UnprotectString(string ciphertextEnvelope, string purpose, AuthenticatedContext associatedData, int expectedKeyVersion = 0)
Decrypts and authenticates a `v1.<base64url>` envelope into a UTF-8 string, scrubbing intermediate decrypted byte buffers via `ZeroMemory` before returning.
- ciphertextEnvelope: string
- The persisted `v1.<base64url>` envelope string.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: AuthenticatedContext
- The external authenticated context (AAD) to verify.
- expectedKeyVersion: int
- Optional expected key version.
Returns: A `Result<T>` containing the decrypted UTF-8 string on success.
methodUnprotectString
public Result<string> UnprotectString(string ciphertextEnvelope, string purpose, ReadOnlySpan<byte> associatedData, int expectedKeyVersion = 0)
Decrypts and authenticates a `v1.<base64url>` envelope into a UTF-8 string, scrubbing intermediate decrypted byte buffers via `ZeroMemory` before returning.
- ciphertextEnvelope: string
- The persisted `v1.<base64url>` envelope string.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: ReadOnlySpan<byte>
- The external authenticated context (AAD) to verify.
- expectedKeyVersion: int
- Optional expected key version.
Returns: A `Result<T>` containing the decrypted UTF-8 string on success.
methodUnprotectString
public Result<string> UnprotectString(string ciphertextEnvelope, string purpose, string? associatedDataContext, int expectedKeyVersion = 0)
Decrypts and authenticates a `v1.<base64url>` envelope into a UTF-8 string, scrubbing intermediate decrypted byte buffers via `ZeroMemory` before returning.
- ciphertextEnvelope: string
- The persisted `v1.<base64url>` envelope string.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedDataContext: string?
- expectedKeyVersion: int
- Optional expected key version.
Returns: A `Result<T>` containing the decrypted UTF-8 string on success.
methodUnprotectStringFromBytes
public Result<string> UnprotectStringFromBytes(ReadOnlySpan<byte> ciphertextPayload, string purpose, AuthenticatedContext associatedData, int expectedKeyVersion = 0)
Decrypts and authenticates a compact binary versioned AEAD payload into a UTF-8 string, scrubbing intermediate buffers.
- ciphertextPayload: ReadOnlySpan<byte>
- The binary versioned AEAD payload.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: AuthenticatedContext
- The external authenticated context (AAD) to verify.
- expectedKeyVersion: int
- Optional expected key version.
Returns: A `Result<T>` containing the decrypted UTF-8 string on success.
methodUnprotectStringFromBytes
public Result<string> UnprotectStringFromBytes(ReadOnlySpan<byte> ciphertextPayload, string purpose, ReadOnlySpan<byte> associatedData, int expectedKeyVersion = 0)
Decrypts and authenticates a compact binary versioned AEAD payload into a UTF-8 string, scrubbing intermediate buffers.
- ciphertextPayload: ReadOnlySpan<byte>
- The binary versioned AEAD payload.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: ReadOnlySpan<byte>
- The external authenticated context (AAD) to verify.
- expectedKeyVersion: int
- Optional expected key version.
Returns: A `Result<T>` containing the decrypted UTF-8 string on success.
methodUnprotectStringFromBytes
public Result<string> UnprotectStringFromBytes(ReadOnlySpan<byte> ciphertextPayload, string purpose, string? associatedDataContext, int expectedKeyVersion = 0)
Decrypts and authenticates a compact binary versioned AEAD payload into a UTF-8 string, scrubbing intermediate buffers.
- ciphertextPayload: ReadOnlySpan<byte>
- The binary versioned AEAD payload.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedDataContext: string?
- expectedKeyVersion: int
- Optional expected key version.
Returns: A `Result<T>` containing the decrypted UTF-8 string on success.
methodUnprotectToSecretBuffer
public Result<ISecretBuffer> UnprotectToSecretBuffer(string ciphertextEnvelope, string purpose, AuthenticatedContext associatedData, int expectedKeyVersion = 0)
Decrypts and authenticates a `v1.<base64url>` envelope directly into a zeroizable `ISecretBuffer`.
- ciphertextEnvelope: string
- The persisted `v1.<base64url>` envelope string.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: AuthenticatedContext
- The external authenticated context (AAD) to verify.
- expectedKeyVersion: int
- Optional expected key version.
Returns: A `Result<T>` containing the decrypted `ISecretBuffer` on success.
methodUnprotectToSecretBuffer
public Result<ISecretBuffer> UnprotectToSecretBuffer(string ciphertextEnvelope, string purpose, ReadOnlySpan<byte> associatedData, int expectedKeyVersion = 0)
Decrypts and authenticates a `v1.<base64url>` envelope directly into a zeroizable `ISecretBuffer`.
- ciphertextEnvelope: string
- The persisted `v1.<base64url>` envelope string.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedData: ReadOnlySpan<byte>
- The external authenticated context (AAD) to verify.
- expectedKeyVersion: int
- Optional expected key version.
Returns: A `Result<T>` containing the decrypted `ISecretBuffer` on success.
methodUnprotectToSecretBuffer
public Result<ISecretBuffer> UnprotectToSecretBuffer(string ciphertextEnvelope, string purpose, string? associatedDataContext, int expectedKeyVersion = 0)
Decrypts and authenticates a `v1.<base64url>` envelope directly into a zeroizable `ISecretBuffer`.
- ciphertextEnvelope: string
- The persisted `v1.<base64url>` envelope string.
- purpose: string
- The non-empty cryptographic purpose label used for HKDF subkey domain separation.
- associatedDataContext: string?
- expectedKeyVersion: int
- Optional expected key version.
Returns: A `Result<T>` containing the decrypted `ISecretBuffer` on success.
propertyActiveKeyVersion
public int ActiveKeyVersion { get; }
Gets the currently active master key version used for new encryption operations.
propertyIsDisposed
public bool IsDisposed { get; }
Gets a value indicating whether this instance has been disposed.
propertyRequireAssociatedData
public bool RequireAssociatedData { get; }
Gets a value indicating whether non-empty associated data (AAD) is mandatory for all protect and unprotect operations.