feat: Implementieren der Verschlüsselungs- und Entschlüsselungsdienste mit AES und Integration in die API
- Hinzufügen der `Encryptor`-Klasse für AES-Verschlüsselung und -Entschlüsselung. - Implementierung des `EncryptionController` zur Bereitstellung von Endpunkten für Verschlüsselung, Entschlüsselung und Generierung von Verschlüsselungsparametern. - Erweiterung der DI-Konfiguration mit `AddEncryptor`-Erweiterungsmethode und Integration in `Program.cs`. - Bedingte Registrierung des `EncryptionController` basierend auf der Konfiguration `UseEncryptor`, um sicherzustellen, dass der Controller nur bei Bedarf verfügbar ist. - Implementierung von Lazy Loading für die Verbindungszeichenfolge in `UserManagerDbContext` zur sicheren Handhabung von verschlüsselten Verbindungszeichenfolgen.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using DigitalData.UserManager.Application.Services;
|
||||
using DigitalData.UserManager.Application.Services.Options;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace DigitalData.UserManager.API.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class EncryptionController : ControllerBase
|
||||
{
|
||||
private readonly Encryptor _encryptor;
|
||||
|
||||
public EncryptionController(Encryptor encryptor)
|
||||
{
|
||||
_encryptor = encryptor;
|
||||
}
|
||||
|
||||
[HttpPost("encrypt")]
|
||||
public IActionResult Encrypt([FromQuery] string plainText, [FromBody] EncryptionParameters? options = null)
|
||||
{
|
||||
string cipherText = options is null
|
||||
? _encryptor.Encrypt(plainText)
|
||||
: Encryptor.Encrypt(plainText, options.Key, options.IV);
|
||||
|
||||
return Ok(cipherText);
|
||||
}
|
||||
|
||||
[HttpPost("decrypt")]
|
||||
public IActionResult Decrypt([FromQuery] string cipherText, [FromBody] EncryptionParameters? options = null)
|
||||
{
|
||||
var plainText = options is null
|
||||
? _encryptor.Decrypt(cipherText)
|
||||
: Encryptor.Decrypt(cipherText, options.Key, options.IV);
|
||||
|
||||
return Ok(plainText);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Generate()
|
||||
{
|
||||
var param = Encryptor.GenerateParameters();
|
||||
return Ok(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user