Skip to content

IJsonWebTokenEncryptor Interface

Defines the contract for JSON Web Encryption (JWE) token encryption and decryption services.

C#
public interface IJsonWebTokenEncryptor

Remarks

The payload is exchanged as bytes rather than a string: the CEK protects arbitrary octets, and a later feature encrypts a binary (non-text) payload, so a byte contract fits every caller while a JWS-wrapping caller does the trivial UTF-8 conversion. Encryption is asynchronous and cancellable so key management (unwrap/agree) can be served by an external key custodian over a network round-trip; the in-process path completes synchronously inside the task.

Methods

IJsonWebTokenEncryptor.DecryptAsync(string[], IAsyncEnumerable<JsonWebKey>, CancellationToken) Method

Validates and decrypts a JWE token. Implements RFC 7516 (JWE) decryption.

C#
System.Threading.Tasks.Task<Abblix.Utils.Result<byte[],Abblix.Jwt.JwtValidationError>> DecryptAsync(string[] jwtParts, System.Collections.Generic.IAsyncEnumerable<Abblix.Jwt.JsonWebKey> decryptionKeys, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

jwtParts System.String[]

The base64url-encoded JWE string parts.

decryptionKeys System.Collections.Generic.IAsyncEnumerable<JsonWebKey>

The decryption keys to try.

cancellationToken System.Threading.CancellationToken

Cancels enumeration of the decryption-key source and any external unwrap.

Returns

System.Threading.Tasks.Task<Abblix.Utils.Result<System.Byte[],JwtValidationError>>
A result containing either the decrypted plaintext bytes or a validation error.

IJsonWebTokenEncryptor.EncryptAsync(byte[], JsonWebKey, string, string, string, CancellationToken) Method

Encrypts a plaintext payload (typically an inner JWS) into a JWE token. Implements RFC 7516 (JWE) encryption.

C#
System.Threading.Tasks.Task<string> EncryptAsync(byte[] plaintext, Abblix.Jwt.JsonWebKey encryptionKey, string? tokenType, string keyEncryptionAlgorithm, string contentEncryptionAlgorithm, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

plaintext System.Byte[]

The bytes to encrypt; a JWS-wrapping caller UTF-8 encodes the inner JWS.

encryptionKey JsonWebKey

The JSON Web Key to use for encryption.

tokenType System.String

The token type to set in the JWE header.

keyEncryptionAlgorithm System.String

The key encryption algorithm (e.g. RSA-OAEP-256).

contentEncryptionAlgorithm System.String

The content encryption algorithm (e.g. A256CBC-HS512).

cancellationToken System.Threading.CancellationToken

Cancels a network-backed external key-management round-trip.

Returns

System.Threading.Tasks.Task<System.String>
The JWE compact serialization string.