diff --git a/DigitalData.Core.Abstractions/Security/ICryptFactory.cs b/DigitalData.Core.Abstractions/Security/ICryptFactory.cs index 2903775..a1d1a12 100644 --- a/DigitalData.Core.Abstractions/Security/ICryptFactory.cs +++ b/DigitalData.Core.Abstractions/Security/ICryptFactory.cs @@ -4,19 +4,19 @@ namespace DigitalData.Core.Abstractions.Security { public interface ICryptFactory { - public int KeySizeInBits { get; init; } + int KeySizeInBits { get; init; } - public string PbePassword { init; } + string PbePassword { init; } - public PbeEncryptionAlgorithm PbeEncryptionAlgorithm { get; init; } + PbeEncryptionAlgorithm PbeEncryptionAlgorithm { get; init; } - public HashAlgorithmName PbeHashAlgorithmName { get; init; } + HashAlgorithmName PbeHashAlgorithmName { get; init; } - public int PbeIterationCount { get; init; } + int PbeIterationCount { get; init; } - public PbeParameters PbeParameters { get; } + PbeParameters PbeParameters { get; } - public string EncryptedPrivateKeyPemLabel { get; init; } + string EncryptedPrivateKeyPemLabel { get; init; } string CreateRSAPrivateKeyPem(int? keySizeInBits = null); @@ -26,5 +26,9 @@ namespace DigitalData.Core.Abstractions.Security PbeEncryptionAlgorithm? pbeEncryptionAlgorithm = null, HashAlgorithmName? hashAlgorithmName = null, int? iterationCount = null); + + IRSADecryptor this[string key] { get; } + + bool TryGetRSADecryptor(string key, out IRSADecryptor? decryptor); } } \ No newline at end of file diff --git a/DigitalData.Core.Security/CryptFactory.cs b/DigitalData.Core.Security/CryptFactory.cs index 0e7c5b1..6481d74 100644 --- a/DigitalData.Core.Security/CryptFactory.cs +++ b/DigitalData.Core.Security/CryptFactory.cs @@ -26,10 +26,16 @@ namespace DigitalData.Core.Security public string EncryptedPrivateKeyPemLabel { get; init; } = "ENCRYPTED PRIVATE KEY"; - public CryptFactory(ILogger? logger = null) + public IDictionary Decryptors { get; init; } + + public IRSADecryptor this[string key] { get => Decryptors[key]; set => Decryptors[key] = value; } + + public CryptFactory(ILogger? logger = null, IDictionary? decryptors = null) { _lazyPbeParameters = new(() => new PbeParameters(PbeEncryptionAlgorithm, PbeHashAlgorithmName, PbeIterationCount)); + Decryptors = decryptors ?? new Dictionary(); + logger?.LogInformation("CryptFactory initialized. Core.Secrets version: {Version}, Created on: {CreationDate}.", Secrets.Version, Secrets.CreationDate.ToString("dd.MM.yyyy")); } @@ -58,5 +64,7 @@ namespace DigitalData.Core.Security return new string(pemChars); } + + public bool TryGetRSADecryptor(string key, out IRSADecryptor? decryptor) => _decryptors.TryGetValue(key, out decryptor); } } \ No newline at end of file