29 lines
809 B
C#
29 lines
809 B
C#
using DigitalData.Core.Abstractions.Security;
|
|
using DigitalData.Core.Security.Extensions;
|
|
|
|
namespace DigitalData.Core.Security
|
|
{
|
|
public class RSADecryptor : RSACryptographer, IRSADecryptor, IRSACryptographer
|
|
{
|
|
public required string PrivateKeyPem
|
|
{
|
|
init => _rsa.ImportFromPem(value);
|
|
}
|
|
|
|
public IRSAEncryptor Encryptor
|
|
{
|
|
get
|
|
{
|
|
return new RSAEncryptor()
|
|
{
|
|
PublicKeyPem = _rsa.ExportRSAPublicKeyPem(),
|
|
Padding = Padding
|
|
};
|
|
}
|
|
}
|
|
|
|
public byte[] Decrypt(byte[] data) => _rsa.Decrypt(data, Padding);
|
|
|
|
public string Decrypt(string data) => _rsa.Decrypt(data.Base64ToByte(), Padding).BytesToString();
|
|
}
|
|
} |