refactor(RSADecryptor): Konstruktionsmethode intern gemacht

This commit is contained in:
Developer 02 2024-11-18 17:35:01 +01:00
parent 4e615d7e39
commit ee3060158e

View File

@ -22,22 +22,12 @@ namespace DigitalData.Core.Security
} }
} }
public RSADecryptor() { } internal RSADecryptor() { }
public RSADecryptor(string pem, string? password = null)
{
Pem = pem;
Password = password;
Initialize();
}
[OnDeserialized] [OnDeserialized]
private void OnDeserialized(StreamingContext context) private void OnDeserialized(StreamingContext context) => Init();
{
Initialize();
}
private void Initialize() private IRSADecryptor Init()
{ {
if (string.IsNullOrWhiteSpace(Pem)) if (string.IsNullOrWhiteSpace(Pem))
throw new InvalidOperationException("Pem cannot be null or empty."); throw new InvalidOperationException("Pem cannot be null or empty.");
@ -46,6 +36,8 @@ namespace DigitalData.Core.Security
_rsa.ImportFromPem(Pem); _rsa.ImportFromPem(Pem);
else else
_rsa.ImportFromEncryptedPem(Pem, Password.AsSpan()); _rsa.ImportFromEncryptedPem(Pem, Password.AsSpan());
return this;
} }
public byte[] Decrypt(byte[] data) => _rsa.Decrypt(data, Padding); public byte[] Decrypt(byte[] data) => _rsa.Decrypt(data, Padding);