From eced1a5afc5abfcf082cf50392a34ad4c985a3b9 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Mon, 16 Dec 2024 10:01:09 +0100 Subject: [PATCH] =?UTF-8?q?feat(RSAFactory):=20Optionale=20Verschl=C3=BCss?= =?UTF-8?q?elungseingabe=20in=20CreatePrivateKeyPem=20Methode=20hinzugef?= =?UTF-8?q?=C3=BCgt.=20=20-=20Falsch=20als=20Standard=20eingestellt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DigitalData.Core.Abstractions/Security/IRSAFactory.cs | 6 +++--- DigitalData.Core.Security/Cryptographer/RSAFactory.cs | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/DigitalData.Core.Abstractions/Security/IRSAFactory.cs b/DigitalData.Core.Abstractions/Security/IRSAFactory.cs index d1347ff..28a776a 100644 --- a/DigitalData.Core.Abstractions/Security/IRSAFactory.cs +++ b/DigitalData.Core.Abstractions/Security/IRSAFactory.cs @@ -4,16 +4,16 @@ namespace DigitalData.Core.Abstractions.Security { public interface IRSAFactory { - string CreatePrivateKeyPem(int? keySizeInBits = null); + string CreatePrivateKeyPem(int? keySizeInBits = null, bool encrypt = false); - public string CreateEncryptedPrivateKeyPem( + string CreateEncryptedPrivateKeyPem( PbeEncryptionAlgorithm? pbeEncryptionAlgorithm = null, HashAlgorithmName? hashAlgorithmName = null, int? iterationCount = null, int? keySizeInBits = null, string? password = null); - public string CreateEncryptedPrivateKeyPem( + string CreateEncryptedPrivateKeyPem( PbeParameters pbeParameters, int? keySizeInBits = null, string? password = null); diff --git a/DigitalData.Core.Security/Cryptographer/RSAFactory.cs b/DigitalData.Core.Security/Cryptographer/RSAFactory.cs index 9f10a06..e928280 100644 --- a/DigitalData.Core.Security/Cryptographer/RSAFactory.cs +++ b/DigitalData.Core.Security/Cryptographer/RSAFactory.cs @@ -11,8 +11,9 @@ namespace DigitalData.Core.Security.Cryptographer public RSAFactory(IOptions options) => _params = options.Value; - public string CreatePrivateKeyPem(int? keySizeInBits = null) - => RSA.Create(keySizeInBits ?? _params.KeySizeInBits).ExportRSAPrivateKeyPem(); + public string CreatePrivateKeyPem(int? keySizeInBits = null, bool encrypt = false) => encrypt + ? CreateEncryptedPrivateKeyPem(keySizeInBits: keySizeInBits) + : RSA.Create(keySizeInBits ?? _params.KeySizeInBits).ExportRSAPrivateKeyPem(); public string CreateEncryptedPrivateKeyPem( PbeEncryptionAlgorithm? pbeEncryptionAlgorithm = null,