Files
DigitalData.MessagingService/src/DigitalData.EmailProfiler.Infrastructure/Services/DataProtectionEncryptionService.cs
TekH 6a5e0a6086 Refactor EmailAccountDto and improve encryption logic
Refactored `EmailAccountDto` to focus on SMTP-related properties, removing unused fields. Updated `DependencyInjection` to configure data protection with a new key storage path. Simplified `DataProtectionEncryptionService` by removing redundant checks and error handling for encryption and decryption methods.
2026-07-23 13:06:42 +02:00

24 lines
727 B
C#

using DigitalData.EmailProfiler.Application.Common.Interfaces;
using Microsoft.AspNetCore.DataProtection;
namespace DigitalData.EmailProfiler.Infrastructure.Services;
/// <summary>
/// Encryption service using ASP.NET Core Data Protection API.
/// Passwords are encrypted at rest in the database.
/// </summary>
public class DataProtectionEncryptionService(IDataProtectionProvider Provider) : IEncryptionService
{
private readonly IDataProtector Protector = Provider.CreateProtector("EmailProfiler.Passwords");
public string Encrypt(string plainText)
{
return Protector.Protect(plainText);
}
public string Decrypt(string cipherText)
{
return Protector.Unprotect(cipherText);
}
}