Added certificate protected data protection keys #124

Merged
khwezi merged 1 commits from dataprotection into master 2026-06-14 11:27:32 +02:00
2 changed files with 5 additions and 1 deletions
+4
View File
@@ -5,6 +5,7 @@ using LiteCharms.Features.Api.Sdk;
using LiteCharms.Features.Postgres;
using Microsoft.AspNetCore.Hosting;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
namespace LiteCharms.Features.Extensions;
@@ -56,7 +57,10 @@ public static class Api
public static IServiceCollection AddLiteCharmsWebSecurity(this IServiceCollection services, IConfiguration configuration)
{
var certificate = X509CertificateLoader.LoadPkcs12(Convert.FromBase64String(configuration["DataProtection:Certificate"]!), configuration["DataProtection:Password"]);
services.AddDataProtection().PersistKeysToDbContext<DataProtectionDbContext>()
.ProtectKeysWithCertificate(certificate)
.SetApplicationName("LiteCharmsApp");
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));