diff --git a/DigitalData.Core.Abstractions/Security/IRSACryptographer.cs b/DigitalData.Core.Abstractions/Security/IRSACryptographer.cs index 2da1e43..acf7320 100644 --- a/DigitalData.Core.Abstractions/Security/IRSACryptographer.cs +++ b/DigitalData.Core.Abstractions/Security/IRSACryptographer.cs @@ -3,7 +3,9 @@ namespace DigitalData.Core.Abstractions.Security { public interface IRSACryptographer - { + { + public string Pem { get; init; } + public RSAEncryptionPadding Padding { get; init; } } } \ No newline at end of file diff --git a/DigitalData.Core.Abstractions/Security/IRSADecryptor.cs b/DigitalData.Core.Abstractions/Security/IRSADecryptor.cs index e1fb7ee..f3b9258 100644 --- a/DigitalData.Core.Abstractions/Security/IRSADecryptor.cs +++ b/DigitalData.Core.Abstractions/Security/IRSADecryptor.cs @@ -2,8 +2,6 @@ { public interface IRSADecryptor : IRSACryptographer { - public string PrivateKeyPem { get; init; } - public string? Password { get; init; } public IRSAEncryptor Encryptor { get; } diff --git a/DigitalData.Core.Abstractions/Security/IRSAEncryptor.cs b/DigitalData.Core.Abstractions/Security/IRSAEncryptor.cs index b3fa28c..cc624d5 100644 --- a/DigitalData.Core.Abstractions/Security/IRSAEncryptor.cs +++ b/DigitalData.Core.Abstractions/Security/IRSAEncryptor.cs @@ -2,8 +2,6 @@ { public interface IRSAEncryptor : IRSACryptographer { - public string PublicKeyPem { get; init; } - public byte[] Encrypt(byte[] data); public string Encrypt(string data); diff --git a/DigitalData.Core.Security/RSACryptographer.cs b/DigitalData.Core.Security/RSACryptographer.cs index d6f65ec..72959a6 100644 --- a/DigitalData.Core.Security/RSACryptographer.cs +++ b/DigitalData.Core.Security/RSACryptographer.cs @@ -4,7 +4,9 @@ using System.Security.Cryptography; 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(); diff --git a/DigitalData.Core.Security/RSADecryptor.cs b/DigitalData.Core.Security/RSADecryptor.cs index 87d60dd..8078837 100644 --- a/DigitalData.Core.Security/RSADecryptor.cs +++ b/DigitalData.Core.Security/RSADecryptor.cs @@ -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); diff --git a/DigitalData.Core.Security/RSAEncryptor.cs b/DigitalData.Core.Security/RSAEncryptor.cs index 5384291..e0c6334 100644 --- a/DigitalData.Core.Security/RSAEncryptor.cs +++ b/DigitalData.Core.Security/RSAEncryptor.cs @@ -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);