Skip to content

EncryptionServiceCollectionExtensions Class

Enables the JWE key-management algorithms AddJsonWebTokens(this IServiceCollection) deliberately leaves out: RSA1_5 and PBES2.

C#
public static class EncryptionServiceCollectionExtensions

Inheritance System.Object → EncryptionServiceCollectionExtensions

Methods

EncryptionServiceCollectionExtensions.AddPbes2KeyManagement(this IServiceCollection) Method

Enables the PBES2 password-based key management algorithms (PBES2-HS256+A128KW, PBES2-HS384+A192KW, PBES2-HS512+A256KW; RFC 7518 Section 4.8) for both producing and consuming JWE tokens. They are deliberately not part of AddJsonWebTokens(this IServiceCollection): the 'p2c' header of an inbound token dictates PBKDF2 work performed before any authentication of the token (the CVE-2022-36083 class of denial of service), and because JWE decryption keys are matched by key identifier, an octet key configured for another key-management algorithm could otherwise be driven into the PBKDF2 path by an attacker-chosen 'alg' header. Accepting password-based key management is therefore an explicit hosting decision. The iteration count of an inbound token is bounded to [1000, 10,000] even when enabled.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddPbes2KeyManagement(this Microsoft.Extensions.DependencyInjection.IServiceCollection services);

Parameters

services Microsoft.Extensions.DependencyInjection.IServiceCollection

The service collection to register the PBES2 encryptors in.

Returns

Microsoft.Extensions.DependencyInjection.IServiceCollection
The service collection for method chaining.

EncryptionServiceCollectionExtensions.AddRsaPkcs1KeyManagement(this IServiceCollection) Method

Enables the RSA1_5 (RSAES-PKCS1-v1_5) key management algorithm (RFC 7518 Section 4.2) for both producing and consuming JWE tokens. It is deliberately not part of AddJsonWebTokens(this IServiceCollection): NIST SP 800-131A Rev. 2 disallows RSA key transport with PKCS#1 v1.5 padding after 2023, and RFC 8725 section 3.2 prescribes preferring RSAES-OAEP - interoperating with a legacy peer that still requires it is an explicit hosting decision. The padding's Bleichenbacher decryption oracle stays closed for opted-in hosts by the RFC 7516 section 11.5 mitigation in Abblix.Jwt.Encryption.JweKeyAttempt: a CEK that fails to decrypt is replaced with a random CEK and the AEAD step still runs, so a decryption failure is processed identically regardless of padding validity.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddRsaPkcs1KeyManagement(this Microsoft.Extensions.DependencyInjection.IServiceCollection services);

Parameters

services Microsoft.Extensions.DependencyInjection.IServiceCollection

The service collection to register the encryptor in.

Returns

Microsoft.Extensions.DependencyInjection.IServiceCollection
The service collection for method chaining.