fix(Core.Security): pem-Importprozess in den Initilizer mehetods verschoben
This commit is contained in:
parent
eccf2b32ce
commit
26a68cd477
@ -5,7 +5,7 @@ namespace DigitalData.Core.Security
|
|||||||
{
|
{
|
||||||
public class RSACryptographer : IRSACryptographer
|
public class RSACryptographer : IRSACryptographer
|
||||||
{
|
{
|
||||||
public required string Pem { get; init; }
|
public required virtual string Pem { get; init; }
|
||||||
|
|
||||||
public required RSAEncryptionPadding Padding { get; init; }
|
public required RSAEncryptionPadding Padding { get; init; }
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using DigitalData.Core.Abstractions.Security;
|
using DigitalData.Core.Abstractions.Security;
|
||||||
using DigitalData.Core.Security.Extensions;
|
using DigitalData.Core.Security.Extensions;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace DigitalData.Core.Security
|
namespace DigitalData.Core.Security
|
||||||
{
|
{
|
||||||
@ -21,8 +22,26 @@ namespace DigitalData.Core.Security
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RSADecryptor()
|
public RSADecryptor() { }
|
||||||
|
|
||||||
|
public RSADecryptor(string pem, string? password = null)
|
||||||
{
|
{
|
||||||
|
Pem = pem;
|
||||||
|
Password = password;
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
[OnDeserialized]
|
||||||
|
private void OnDeserialized(StreamingContext context)
|
||||||
|
{
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Initialize()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(Pem))
|
||||||
|
throw new InvalidOperationException("Pem cannot be null or empty.");
|
||||||
|
|
||||||
if (Password is null)
|
if (Password is null)
|
||||||
_rsa.ImportFromPem(Pem);
|
_rsa.ImportFromPem(Pem);
|
||||||
else
|
else
|
||||||
|
|||||||
@ -5,9 +5,17 @@ namespace DigitalData.Core.Security
|
|||||||
{
|
{
|
||||||
public class RSAEncryptor : RSACryptographer, IRSAEncryptor, IRSACryptographer
|
public class RSAEncryptor : RSACryptographer, IRSAEncryptor, IRSACryptographer
|
||||||
{
|
{
|
||||||
public RSAEncryptor()
|
public override required string Pem
|
||||||
{
|
{
|
||||||
_rsa.ImportFromPem(Pem);
|
get => base.Pem;
|
||||||
|
init
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(Pem))
|
||||||
|
throw new InvalidOperationException("Pem cannot be null or empty.");
|
||||||
|
|
||||||
|
_rsa.ImportFromPem(base.Pem);
|
||||||
|
base.Pem = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] Encrypt(byte[] data) => _rsa.Encrypt(data, Padding);
|
public byte[] Encrypt(byte[] data) => _rsa.Encrypt(data, Padding);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user