refactor(RSADecryptor): Verbesserung der PEM-Initialisierung und Konsistenz
- Die `Pem`-Eigenschaft aktualisiert, sodass während der Initialisierung automatisch `Init()` aufgerufen wird, um eine konsistente Einrichtung sicherzustellen. - Die Methode `SetPem` überarbeitet, um nach dem Setzen des PEM-Werts `Init()` aufzurufen. - Die Methode `Init()` verbessert, um null- oder leere PEM-Werte robuster zu behandeln. - Fehlermeldungen für mehr Klarheit und bessere Debugging-Unterstützung verbessert. - Interne RSA-Initialisierungslogik an die Verarbeitung von Verschlüsselungen angepasst.
This commit is contained in:
parent
eced1a5afc
commit
58c8520c08
@ -69,8 +69,6 @@ namespace DigitalData.Core.Security.Config
|
||||
Task.Run(async () => await File.WriteAllTextAsync(path: path, pem));
|
||||
}
|
||||
}
|
||||
|
||||
decryptor.Init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,15 @@ namespace DigitalData.Core.Security.Cryptographer
|
||||
{
|
||||
private string? _pem;
|
||||
|
||||
public override string Pem { get => _pem ?? throw PemIsNullException; init => _pem = value; }
|
||||
public override string Pem
|
||||
{
|
||||
get => _pem ?? throw PemIsNullException;
|
||||
init
|
||||
{
|
||||
_pem = value;
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsPemNull => _pem is null;
|
||||
|
||||
@ -31,11 +39,15 @@ namespace DigitalData.Core.Security.Cryptographer
|
||||
|
||||
public string Decrypt(string data) => RSA.Decrypt(data.Base64ToByte(), Padding).BytesToString();
|
||||
|
||||
internal void SetPem(string pem) => _pem = pem;
|
||||
|
||||
public void Init()
|
||||
internal void SetPem(string pem)
|
||||
{
|
||||
if (_pem is null)
|
||||
_pem = pem;
|
||||
Init();
|
||||
}
|
||||
|
||||
private void Init()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_pem))
|
||||
throw PemIsNullException;
|
||||
|
||||
if (IsEncrypted)
|
||||
@ -44,6 +56,6 @@ namespace DigitalData.Core.Security.Cryptographer
|
||||
RSA.ImportFromPem(Pem);
|
||||
}
|
||||
|
||||
private InvalidOperationException PemIsNullException => new($"Pem is not initialized. Please ensure that the PEM is set or properly loaded from the file. Issuer: {Issuer}, Audience: {Audience}.");
|
||||
private InvalidOperationException PemIsNullException => new($"Pem is null or empty. Issuer: {Issuer}, Audience: {Audience}.");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user