Makes using the Microsoft.AspNet.DataProtection package more convenient, especially when using IAuthenticatedEncryptor.
License
—
Deps
3
Install Size
—
Vulns
✓ 0
Published
Nov 26, 2025
$ dotnet add package fm.Extensions.DataProtectionMakes using the Microsoft.AspNet.DataProtection package more convenient, especially when using IAuthenticatedEncryptor.
[TestClass]
public sealed class ExampleTests : ServiceTestsBase // Provided by fm.Extensions.Testing.DependencyInjection
{
protected override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);
// Add the AuthenticatedEncryptorFactory for creating encryptors.
services.AddSingleton<IAuthenticatedEncryptorFactory, AuthenticatedEncryptorFactory>();
}
[TestMethod]
public void RandomTest()
{
// Create a secret
SecretKey key = new SecretKey(
new Secret("Password"u8.ToArray()),
this.GetRequiredService<IAuthenticatedEncryptorFactory>());
// Create an encryptor to encrypt and decrypt data
IAuthenticatedEncryptor encryptor = key.CreateEncryptor().ShouldNotBeNull();
byte[] ciphertext = encryptor.Encrypt("Input", "AAD").ShouldCount(80, "Should be 80 bytes.");
encryptor.DecryptToString(ciphertext, "AAD").ShouldBe("Input");
}
}
The main types provided by this library are:
AuthenticatedEncryptorExtensionsEncryptorEncodingSecretKey