From eccf2b32cefa1545bb5bcf46c09d14c25c85da8f Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Mon, 18 Nov 2024 14:39:18 +0100 Subject: [PATCH] =?UTF-8?q?Refactor(Core.Security):=20Getrennte=20Pem-Eige?= =?UTF-8?q?nschaften=20f=C3=BCr=20=C3=B6ffentliche=20und=20private=20Schl?= =?UTF-8?q?=C3=BCssel=20wurden=20entfernt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Pem-Eigenschaft in der Hauptklasse RSACryptographer erstellt --- .../Security/IRSACryptographer.cs | 4 +++- DigitalData.Core.Abstractions/Security/IRSADecryptor.cs | 2 -- DigitalData.Core.Abstractions/Security/IRSAEncryptor.cs | 2 -- DigitalData.Core.Security/RSACryptographer.cs | 4 +++- DigitalData.Core.Security/RSADecryptor.cs | 8 +++----- DigitalData.Core.Security/RSAEncryptor.cs | 5 ++--- 6 files changed, 11 insertions(+), 14 deletions(-) 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);