refactor(Privatekey): Die Klasse decryptor wurde erstellt und die Verschlüsselungsfunktionen für eine einfache und saubere Konfiguration dorthin verschoben.

This commit is contained in:
Developer 02
2025-01-08 18:45:36 +01:00
parent 608d266d1c
commit 9f0facc487
11 changed files with 43 additions and 30 deletions

View File

@@ -8,12 +8,12 @@ namespace DigitalData.Core.Security
{
public class Cryptograph : RSAFactory<CryptographParams>, ICryptograph, IAsymmetricKeyFactory
{
public IEnumerable<IAsymmetricPrivateKey> PrivateKeys { get; }
public IEnumerable<IAsymmetricDecryptor> Decryptors { get; }
/// <summary>
/// It is a separate decryptor for permanently stored encrypted data. It is assigned to the first Default decryptor by default.
/// </summary>
public IAsymmetricPrivateKey VaultPrivateKey { get; }
public IAsymmetricDecryptor VaultDecryptor { get; }
private readonly Lazy<IEnumerable<IAsymmetricPublicKey>> _lazyPublicKeys;
@@ -25,18 +25,18 @@ namespace DigitalData.Core.Security
{
logger?.LogInformation("Core.Secrets version: {Version}, Created on: {CreationDate}.", Secrets.Version, Secrets.CreationDate.ToString("dd.MM.yyyy"));
if (!_params.PrivateKeys.Any())
if (!_params.Decryptors.Any())
throw new InvalidOperationException(
"Any decryptor is not found. Ensure that at least one decryptor is configured in the provided parameters. " +
"This issue typically arises if the configuration for decryptors is incomplete or missing. " +
"Check the 'Decryptors' collection in the configuration and verify that it contains valid entries."
);
PrivateKeys = _params.PrivateKeys;
Decryptors = _params.Decryptors;
VaultPrivateKey = _params.VaultPrivateKey ?? PrivateKeys.First();
VaultDecryptor = _params.VaultDecryptor ?? Decryptors.First();
_lazyPublicKeys = new(PrivateKeys.Select(decryptor => decryptor.PublicKey));
_lazyPublicKeys = new(Decryptors.Select(decryptor => decryptor.PublicKey));
}
}
}