Tingle.AspNetCore.DataProtection.MongoDB 4.7.0

dotnet add package Tingle.AspNetCore.DataProtection.MongoDB --version 4.7.0
NuGet\Install-Package Tingle.AspNetCore.DataProtection.MongoDB -Version 4.7.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tingle.AspNetCore.DataProtection.MongoDB" Version="4.7.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tingle.AspNetCore.DataProtection.MongoDB --version 4.7.0
#r "nuget: Tingle.AspNetCore.DataProtection.MongoDB, 4.7.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Tingle.AspNetCore.DataProtection.MongoDB as a Cake Addin
#addin nuget:?package=Tingle.AspNetCore.DataProtection.MongoDB&version=4.7.0

// Install Tingle.AspNetCore.DataProtection.MongoDB as a Cake Tool
#tool nuget:?package=Tingle.AspNetCore.DataProtection.MongoDB&version=4.7.0

Tingle.AspNetCore.DataProtection.MongoDB

Web applications often need to store security-sensitive data. Windows provides DPAPI for desktop applications, but this is unsuitable for web applications especially when running in a Docker container. The ASP.NET Core data protection stack provide a simple, easy to use cryptographic API a developer can use to protect data, including key management and rotation.

Microsoft has already provided ways to persist data protection keys to various storage systems.

This package provides the functionality to persist the data protection keys to MongoDB.

Using Dependency Injection

public void ConfigureServices(IServicesCollection services)
{
    services.AddSingleton<IMongoClient>(p => new MongoClient("mongodb://localhost:27017/my-database"));
    services.AddDataProtection()
            .PersistKeysToMongo();
}

Sample Usage

[Route("api/v1/[controller]")]
public class DummyController : ControllerBase
{
    IDataProtector _protector;
    public DummyController(IDataProtectionProvider provider)
    {
        _protector = provider.CreateProtector(nameof(DummyController));
    }

    [HttpGet]
    public Task<IActionResult> TestAsync([FromQuery] string value)
    {
        string protectedPayload = _protector.Protect(value);
        string unprotectedPayload = _protector.Unprotect(protectedPayload);

        // unprotectedPayload and value should be the same

        return Ok();
    }
}

The PersistKeysToMongo can be configured to store keys in databases and collections of your choice. By default, data protection keys will be stored in a database and collection named DataProtection and DataProtection-Keys respectively.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.7.0 147 3/25/2024
4.6.0 227 3/8/2024
4.5.0 582 11/22/2023
4.4.1 117 11/20/2023
4.4.0 108 11/15/2023
4.3.0 252 10/18/2023
4.2.2 285 9/20/2023
4.2.1 215 8/4/2023
4.2.0 249 5/31/2023
4.1.1 129 5/26/2023
4.1.0 118 5/22/2023
4.0.0 274 3/14/2023
2.5.0 503 11/21/2022
2.4.2 684 7/25/2022
2.4.1 587 3/22/2022
2.4.0 414 11/10/2021
2.3.1 427 9/20/2021
2.3.0 435 7/22/2021