Refactor(RSACryptographer): Entfernte Pem initter Methode.

- PrivateKeyPem initter Methode zu RSADecryptor hinzugefügt.
 - PublicKeyPem getter und initter Methoden zu RSAEncryptor hinzugefügt.
This commit is contained in:
Developer 02 2024-11-18 10:33:38 +01:00
parent 0804ea1418
commit 489ca67203
3 changed files with 16 additions and 15 deletions

View File

@ -3,19 +3,11 @@
namespace DigitalData.Core.Security
{
public class RSACryptographer
{
internal RSACryptographer() { }
public required string Pem
{
init
{
_rsa.ImportFromPem(value);
}
}
{
public required RSAEncryptionPadding Padding { get; init; }
protected readonly RSA _rsa = RSA.Create();
internal RSACryptographer() { }
}
}

View File

@ -1,9 +1,12 @@
using System.Security.Cryptography;
namespace DigitalData.Core.Security
namespace DigitalData.Core.Security
{
public class RSADecryptor : RSACryptographer
{
public required string PrivateKeyPem
{
init => _rsa.ImportFromPem(value);
}
public string PublicKeyPem => _rsa.ExportRSAPublicKeyPem();
public RSAEncryptor Encryptor
@ -12,7 +15,7 @@ namespace DigitalData.Core.Security
{
return new ()
{
Pem = PublicKeyPem,
PublicKeyPem = PublicKeyPem,
Padding = Padding
};
}

View File

@ -2,6 +2,12 @@
{
public class RSAEncryptor : RSACryptographer
{
public required string PublicKeyPem
{
get => _rsa.ExportRSAPublicKeyPem();
init => _rsa.ImportFromPem(value);
}
public byte[] Encrypt(byte[] data) => _rsa.Encrypt(data, Padding);
public string Encrypt(string data) => _rsa.Encrypt(data.Base64ToByte(), Padding).BytesToString();