feat: Unterstützung für IRSADecryptor und Verwaltung der RSA-Entschlüsselung in den Klassen ICryptFactory und CryptFactory hinzugefügt
ICryptFactory: - `IRSADecryptor this[string key]`-Indexer für den Zugriff auf Entschlüssler per Schlüssel hinzugefügt. - Methode `TryGetRSADecryptor` für das sichere Abrufen von Entschlüsslern eingeführt. CryptFactory: - `IRSADecryptor`-Indexer für die Verwaltung von Entschlüsslern implementiert. - Ein `Decryptors`-Dictionary hinzugefügt, um RSA-Entschlüssler nach Schlüssel zu speichern. - Konstruktor aktualisiert, um `Decryptors` mit einem bereitgestellten oder leeren Dictionary zu initialisieren. - `TryGetRSADecryptor` zur Entschlüssler-Abfrage implementiert.
This commit is contained in:
parent
1b210714fd
commit
eeb50e837d
@ -4,19 +4,19 @@ namespace DigitalData.Core.Abstractions.Security
|
|||||||
{
|
{
|
||||||
public interface ICryptFactory
|
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);
|
string CreateRSAPrivateKeyPem(int? keySizeInBits = null);
|
||||||
|
|
||||||
@ -26,5 +26,9 @@ namespace DigitalData.Core.Abstractions.Security
|
|||||||
PbeEncryptionAlgorithm? pbeEncryptionAlgorithm = null,
|
PbeEncryptionAlgorithm? pbeEncryptionAlgorithm = null,
|
||||||
HashAlgorithmName? hashAlgorithmName = null,
|
HashAlgorithmName? hashAlgorithmName = null,
|
||||||
int? iterationCount = null);
|
int? iterationCount = null);
|
||||||
|
|
||||||
|
IRSADecryptor this[string key] { get; }
|
||||||
|
|
||||||
|
bool TryGetRSADecryptor(string key, out IRSADecryptor? decryptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26,10 +26,16 @@ namespace DigitalData.Core.Security
|
|||||||
|
|
||||||
public string EncryptedPrivateKeyPemLabel { get; init; } = "ENCRYPTED PRIVATE KEY";
|
public string EncryptedPrivateKeyPemLabel { get; init; } = "ENCRYPTED PRIVATE KEY";
|
||||||
|
|
||||||
public CryptFactory(ILogger<CryptFactory>? logger = null)
|
public IDictionary<string, IRSADecryptor> Decryptors { get; init; }
|
||||||
|
|
||||||
|
public IRSADecryptor this[string key] { get => Decryptors[key]; set => Decryptors[key] = value; }
|
||||||
|
|
||||||
|
public CryptFactory(ILogger<CryptFactory>? logger = null, IDictionary<string, IRSADecryptor>? decryptors = null)
|
||||||
{
|
{
|
||||||
_lazyPbeParameters = new(() => new PbeParameters(PbeEncryptionAlgorithm, PbeHashAlgorithmName, PbeIterationCount));
|
_lazyPbeParameters = new(() => new PbeParameters(PbeEncryptionAlgorithm, PbeHashAlgorithmName, PbeIterationCount));
|
||||||
|
|
||||||
|
Decryptors = decryptors ?? new Dictionary<string, IRSADecryptor>();
|
||||||
|
|
||||||
logger?.LogInformation("CryptFactory initialized. Core.Secrets version: {Version}, Created on: {CreationDate}.", Secrets.Version, Secrets.CreationDate.ToString("dd.MM.yyyy"));
|
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);
|
return new string(pemChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool TryGetRSADecryptor(string key, out IRSADecryptor? decryptor) => _decryptors.TryGetValue(key, out decryptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user