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