**Services Refactored:**
- DevExpressPdfProcessingService: Remove unnecessary try-catch (lines 80-87), add stream position validation
- WindreamDmsService: Mark as [Obsolete] - application now only provides email sending functionality
- MailKitEmailService: Keep MailKit implementation (Limilabs DLL to be added separately)
**Custom Exceptions Added:**
- AuthenticationFailedException: OAuth2/IMAP/SMTP authentication failures
- DmsNotAvailableException: windream COM unavailable
- InvalidPdfException: Invalid PDF stream
- NotFoundException: Entity not found in Repository operations
**Legacy Cleanup:**
- Remove legacy VB.NET projects from solution (EmailProfiler.Common, EmailProfiler.Service)
- Delete legacy/ folder reference
- Clean solution file structure
**Stream Validation:**
- All PDF processing methods now validate stream position (reset to 0 if needed)
- Add CanSeek validation for stream-based operations
**Build Status:** ✅ Successful (0 errors, 15 warnings - all acceptable)
38 lines
1.1 KiB
C#
38 lines
1.1 KiB
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)
|
|
{
|
|
if (string.IsNullOrEmpty(plainText))
|
|
return string.Empty;
|
|
|
|
return Protector.Protect(plainText);
|
|
}
|
|
|
|
public string Decrypt(string cipherText)
|
|
{
|
|
if (string.IsNullOrEmpty(cipherText))
|
|
return string.Empty;
|
|
|
|
try
|
|
{
|
|
return Protector.Unprotect(cipherText);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// If decryption fails, return empty (corrupt data or wrong key)
|
|
return string.Empty;
|
|
}
|
|
}
|
|
}
|