#### [Abblix\.Jwt](https://www.abblix.com/en/docs/api/abblix-jwt 'index')
### [Abblix\.Jwt](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt 'Abblix\.Jwt')

## IJsonWebTokenEncryptor Interface

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

```csharp
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 {#Abblix.Jwt.IJsonWebTokenEncryptor.DecryptAsync(string[],System.Collections.Generic.IAsyncEnumerable_Abblix.Jwt.JsonWebKey_,System.Threading.CancellationToken)}

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

```csharp
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](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String')[\[\]](https://learn.microsoft.com/en-us/dotnet/api/system.array 'System\.Array') {#Abblix.Jwt.IJsonWebTokenEncryptor.DecryptAsync(string[],System.Collections.Generic.IAsyncEnumerable_Abblix.Jwt.JsonWebKey_,System.Threading.CancellationToken).jwtParts}

The base64url\-encoded JWE string parts\.

###### `decryptionKeys` [System\.Collections\.Generic\.IAsyncEnumerable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1 'System\.Collections\.Generic\.IAsyncEnumerable\`1')[JsonWebKey](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1 'System\.Collections\.Generic\.IAsyncEnumerable\`1') {#Abblix.Jwt.IJsonWebTokenEncryptor.DecryptAsync(string[],System.Collections.Generic.IAsyncEnumerable_Abblix.Jwt.JsonWebKey_,System.Threading.CancellationToken).decryptionKeys}

The decryption keys to try\.

###### `cancellationToken` [System\.Threading\.CancellationToken](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken 'System\.Threading\.CancellationToken') {#Abblix.Jwt.IJsonWebTokenEncryptor.DecryptAsync(string[],System.Collections.Generic.IAsyncEnumerable_Abblix.Jwt.JsonWebKey_,System.Threading.CancellationToken).cancellationToken}

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

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[Abblix\.Utils\.Result&lt;](https://www.abblix.com/en/docs/api/abblix-utils/Abblix.Utils.Result_TSuccess_TFailure_ 'Abblix\.Utils\.Result\`2')[System\.Byte](https://learn.microsoft.com/en-us/dotnet/api/system.byte 'System\.Byte')[\[\]](https://learn.microsoft.com/en-us/dotnet/api/system.array 'System\.Array')[,](https://www.abblix.com/en/docs/api/abblix-utils/Abblix.Utils.Result_TSuccess_TFailure_ 'Abblix\.Utils\.Result\`2')[JwtValidationError](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.JwtValidationError 'Abblix\.Jwt\.JwtValidationError')[&gt;](https://www.abblix.com/en/docs/api/abblix-utils/Abblix.Utils.Result_TSuccess_TFailure_ 'Abblix\.Utils\.Result\`2')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
A result containing either the decrypted plaintext bytes or a validation error\.

## IJsonWebTokenEncryptor\.EncryptAsync\(byte\[\], JsonWebKey, string, string, string, CancellationToken\) Method {#Abblix.Jwt.IJsonWebTokenEncryptor.EncryptAsync(byte[],Abblix.Jwt.JsonWebKey,string,string,string,System.Threading.CancellationToken)}

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

```csharp
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](https://learn.microsoft.com/en-us/dotnet/api/system.byte 'System\.Byte')[\[\]](https://learn.microsoft.com/en-us/dotnet/api/system.array 'System\.Array') {#Abblix.Jwt.IJsonWebTokenEncryptor.EncryptAsync(byte[],Abblix.Jwt.JsonWebKey,string,string,string,System.Threading.CancellationToken).plaintext}

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

###### `encryptionKey` [JsonWebKey](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey') {#Abblix.Jwt.IJsonWebTokenEncryptor.EncryptAsync(byte[],Abblix.Jwt.JsonWebKey,string,string,string,System.Threading.CancellationToken).encryptionKey}

The JSON Web Key to use for encryption\.

###### `tokenType` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Jwt.IJsonWebTokenEncryptor.EncryptAsync(byte[],Abblix.Jwt.JsonWebKey,string,string,string,System.Threading.CancellationToken).tokenType}

The token type to set in the JWE header\.

###### `keyEncryptionAlgorithm` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Jwt.IJsonWebTokenEncryptor.EncryptAsync(byte[],Abblix.Jwt.JsonWebKey,string,string,string,System.Threading.CancellationToken).keyEncryptionAlgorithm}

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

###### `contentEncryptionAlgorithm` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Jwt.IJsonWebTokenEncryptor.EncryptAsync(byte[],Abblix.Jwt.JsonWebKey,string,string,string,System.Threading.CancellationToken).contentEncryptionAlgorithm}

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

###### `cancellationToken` [System\.Threading\.CancellationToken](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken 'System\.Threading\.CancellationToken') {#Abblix.Jwt.IJsonWebTokenEncryptor.EncryptAsync(byte[],Abblix.Jwt.JsonWebKey,string,string,string,System.Threading.CancellationToken).cancellationToken}

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

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
The JWE compact serialization string\.
