Refactor(Core.Security): Getrennte Pem-Eigenschaften für öffentliche und private Schlüssel wurden entfernt.
- Pem-Eigenschaft in der Hauptklasse RSACryptographer erstellt
This commit is contained in:
parent
6ff0d0a876
commit
eccf2b32ce
@ -4,6 +4,8 @@ namespace DigitalData.Core.Abstractions.Security
|
||||
{
|
||||
public interface IRSACryptographer
|
||||
{
|
||||
public string Pem { get; init; }
|
||||
|
||||
public RSAEncryptionPadding Padding { get; init; }
|
||||
}
|
||||
}
|
||||
@ -2,8 +2,6 @@
|
||||
{
|
||||
public interface IRSADecryptor : IRSACryptographer
|
||||
{
|
||||
public string PrivateKeyPem { get; init; }
|
||||
|
||||
public string? Password { get; init; }
|
||||
|
||||
public IRSAEncryptor Encryptor { get; }
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
{
|
||||
public interface IRSAEncryptor : IRSACryptographer
|
||||
{
|
||||
public string PublicKeyPem { get; init; }
|
||||
|
||||
public byte[] Encrypt(byte[] data);
|
||||
|
||||
public string Encrypt(string data);
|
||||
|
||||
@ -5,6 +5,8 @@ namespace DigitalData.Core.Security
|
||||
{
|
||||
public class RSACryptographer : IRSACryptographer
|
||||
{
|
||||
public required string Pem { get; init; }
|
||||
|
||||
public required RSAEncryptionPadding Padding { get; init; }
|
||||
|
||||
protected readonly RSA _rsa = RSA.Create();
|
||||
|
||||
@ -5,8 +5,6 @@ namespace DigitalData.Core.Security
|
||||
{
|
||||
public class RSADecryptor : RSACryptographer, IRSADecryptor, IRSACryptographer
|
||||
{
|
||||
public required string PrivateKeyPem { get; init; }
|
||||
|
||||
public string? Password { get; init; }
|
||||
|
||||
public bool IsEncrypted => Password is not null;
|
||||
@ -17,7 +15,7 @@ namespace DigitalData.Core.Security
|
||||
{
|
||||
return new RSAEncryptor()
|
||||
{
|
||||
PublicKeyPem = _rsa.ExportRSAPublicKeyPem(),
|
||||
Pem = _rsa.ExportRSAPublicKeyPem(),
|
||||
Padding = Padding
|
||||
};
|
||||
}
|
||||
@ -26,9 +24,9 @@ namespace DigitalData.Core.Security
|
||||
public RSADecryptor()
|
||||
{
|
||||
if (Password is null)
|
||||
_rsa.ImportFromPem(PrivateKeyPem);
|
||||
_rsa.ImportFromPem(Pem);
|
||||
else
|
||||
_rsa.ImportFromEncryptedPem(PrivateKeyPem, Password.AsSpan());
|
||||
_rsa.ImportFromEncryptedPem(Pem, Password.AsSpan());
|
||||
}
|
||||
|
||||
public byte[] Decrypt(byte[] data) => _rsa.Decrypt(data, Padding);
|
||||
|
||||
@ -5,10 +5,9 @@ namespace DigitalData.Core.Security
|
||||
{
|
||||
public class RSAEncryptor : RSACryptographer, IRSAEncryptor, IRSACryptographer
|
||||
{
|
||||
public required string PublicKeyPem
|
||||
public RSAEncryptor()
|
||||
{
|
||||
get => _rsa.ExportRSAPublicKeyPem();
|
||||
init => _rsa.ImportFromPem(value);
|
||||
_rsa.ImportFromPem(Pem);
|
||||
}
|
||||
|
||||
public byte[] Encrypt(byte[] data) => _rsa.Encrypt(data, Padding);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user