In your Blazor application, modify the Program.cs
file to configure data protection with certificate-based encryption.
using Microsoft.AspNetCore.DataProtection; using System.Security.Cryptography.X509Certificates; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); // Configure Data Protection to use a certificate for key encryption var certificate = X509CertificateLoader.LoadPkcs12FromFile("path_to_certificate.pfx", "password"); builder.Services.AddDataProtection() .ProtectKeysWithCertificate(certificate) .PersistKeysToFileSystem(new DirectoryInfo(keyFolderPath)) .SetApplicationName("ERP"); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.MapBlazorHub(); app.MapFallbackToPage("/_Host"); app.Run();