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:
parent
0804ea1418
commit
489ca67203
@ -4,18 +4,10 @@ namespace DigitalData.Core.Security
|
|||||||
{
|
{
|
||||||
public class RSACryptographer
|
public class RSACryptographer
|
||||||
{
|
{
|
||||||
internal RSACryptographer() { }
|
|
||||||
|
|
||||||
public required string Pem
|
|
||||||
{
|
|
||||||
init
|
|
||||||
{
|
|
||||||
_rsa.ImportFromPem(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public required RSAEncryptionPadding Padding { get; init; }
|
public required RSAEncryptionPadding Padding { get; init; }
|
||||||
|
|
||||||
protected readonly RSA _rsa = RSA.Create();
|
protected readonly RSA _rsa = RSA.Create();
|
||||||
|
|
||||||
|
internal RSACryptographer() { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,9 +1,12 @@
|
|||||||
using System.Security.Cryptography;
|
namespace DigitalData.Core.Security
|
||||||
|
|
||||||
namespace DigitalData.Core.Security
|
|
||||||
{
|
{
|
||||||
public class RSADecryptor : RSACryptographer
|
public class RSADecryptor : RSACryptographer
|
||||||
{
|
{
|
||||||
|
public required string PrivateKeyPem
|
||||||
|
{
|
||||||
|
init => _rsa.ImportFromPem(value);
|
||||||
|
}
|
||||||
|
|
||||||
public string PublicKeyPem => _rsa.ExportRSAPublicKeyPem();
|
public string PublicKeyPem => _rsa.ExportRSAPublicKeyPem();
|
||||||
|
|
||||||
public RSAEncryptor Encryptor
|
public RSAEncryptor Encryptor
|
||||||
@ -12,7 +15,7 @@ namespace DigitalData.Core.Security
|
|||||||
{
|
{
|
||||||
return new ()
|
return new ()
|
||||||
{
|
{
|
||||||
Pem = PublicKeyPem,
|
PublicKeyPem = PublicKeyPem,
|
||||||
Padding = Padding
|
Padding = Padding
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,12 @@
|
|||||||
{
|
{
|
||||||
public class RSAEncryptor : RSACryptographer
|
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 byte[] Encrypt(byte[] data) => _rsa.Encrypt(data, Padding);
|
||||||
|
|
||||||
public string Encrypt(string data) => _rsa.Encrypt(data.Base64ToByte(), Padding).BytesToString();
|
public string Encrypt(string data) => _rsa.Encrypt(data.Base64ToByte(), Padding).BytesToString();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user