using DigitalData.Core.Abstractions.Security; using DigitalData.Core.Security.Extensions; namespace DigitalData.Core.Security { public class RSADecryptor : RSACryptographer, IRSADecryptor, IRSACryptographer { public string? Password { get; init; } public bool IsEncrypted => Password is not null; public IRSAEncryptor Encryptor { get { return new RSAEncryptor() { Pem = _rsa.ExportRSAPublicKeyPem(), Padding = Padding }; } } public RSADecryptor() { if (Password is null) _rsa.ImportFromPem(Pem); else _rsa.ImportFromEncryptedPem(Pem, Password.AsSpan()); } public byte[] Decrypt(byte[] data) => _rsa.Decrypt(data, Padding); public string Decrypt(string data) => _rsa.Decrypt(data.Base64ToByte(), Padding).BytesToString(); } }