refactor(RSACryptographer): Entfernen von _pem, IsPemNull, SetPem, Init und Methoden zur Vereinfachung von RSAEncryptor
This commit is contained in:
@@ -6,6 +6,12 @@ namespace DigitalData.Core.Security.Cryptographer
|
||||
{
|
||||
public class RSADecryptor : RSACryptographer, IRSADecryptor, IRSACryptographer
|
||||
{
|
||||
private string? _pem;
|
||||
|
||||
public override string Pem { get => _pem ?? throw PemIsNullException; init => _pem = value; }
|
||||
|
||||
public bool IsPemNull => _pem is null;
|
||||
|
||||
public bool IsEncrypted { get; init; }
|
||||
|
||||
private readonly Lazy<IRSAEncryptor> _lazyEncryptor;
|
||||
@@ -25,13 +31,19 @@ namespace DigitalData.Core.Security.Cryptographer
|
||||
|
||||
public string Decrypt(string data) => RSA.Decrypt(data.Base64ToByte(), Padding).BytesToString();
|
||||
|
||||
public override void Init()
|
||||
internal void SetPem(string pem) => _pem = pem;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
base.Init();
|
||||
if (_pem is null)
|
||||
throw PemIsNullException;
|
||||
|
||||
if (IsEncrypted)
|
||||
RSA.ImportFromEncryptedPem(Pem, Secrets.PBE_PASSWORD.AsSpan());
|
||||
else
|
||||
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}.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user