feat(RSADecryptor): Aktualisiert für den Import von verschlüsseltem pem
This commit is contained in:
parent
0bb779b7b6
commit
6ff0d0a876
@ -2,7 +2,9 @@
|
||||
{
|
||||
public interface IRSADecryptor : IRSACryptographer
|
||||
{
|
||||
public string PrivateKeyPem { init; }
|
||||
public string PrivateKeyPem { get; init; }
|
||||
|
||||
public string? Password { get; init; }
|
||||
|
||||
public IRSAEncryptor Encryptor { get; }
|
||||
|
||||
|
||||
@ -5,10 +5,11 @@ namespace DigitalData.Core.Security
|
||||
{
|
||||
public class RSADecryptor : RSACryptographer, IRSADecryptor, IRSACryptographer
|
||||
{
|
||||
public required string PrivateKeyPem
|
||||
{
|
||||
init => _rsa.ImportFromPem(value);
|
||||
}
|
||||
public required string PrivateKeyPem { get; init; }
|
||||
|
||||
public string? Password { get; init; }
|
||||
|
||||
public bool IsEncrypted => Password is not null;
|
||||
|
||||
public IRSAEncryptor Encryptor
|
||||
{
|
||||
@ -22,6 +23,14 @@ namespace DigitalData.Core.Security
|
||||
}
|
||||
}
|
||||
|
||||
public RSADecryptor()
|
||||
{
|
||||
if (Password is null)
|
||||
_rsa.ImportFromPem(PrivateKeyPem);
|
||||
else
|
||||
_rsa.ImportFromEncryptedPem(PrivateKeyPem, Password.AsSpan());
|
||||
}
|
||||
|
||||
public byte[] Decrypt(byte[] data) => _rsa.Decrypt(data, Padding);
|
||||
|
||||
public string Decrypt(string data) => _rsa.Decrypt(data.Base64ToByte(), Padding).BytesToString();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user