From b8de148c52c94e2ff73ceed03128e57144a0cf9a Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Fri, 14 Mar 2025 10:47:28 +0100 Subject: [PATCH] refactor: Umbenennung von CryptoFactory in RSAPool und ICryptoFactory in IAsymmetricKeyPool --- .../Security/IAsymmetricKeyFactory.cs | 31 +++++++++---------- .../Security/IAsymmetricKeyPool.cs | 10 ++++++ .../Security/ICryptoFactory.cs | 11 ------- DigitalData.Core.Security/DIExtensions.cs | 2 +- .../Services/JwtSignatureHandler.cs | 4 +-- .../Services/{CryptoFactory.cs => RSAPool.cs} | 4 +-- 6 files changed, 30 insertions(+), 32 deletions(-) create mode 100644 DigitalData.Core.Abstractions/Security/IAsymmetricKeyPool.cs delete mode 100644 DigitalData.Core.Abstractions/Security/ICryptoFactory.cs rename DigitalData.Core.Security/Services/{CryptoFactory.cs => RSAPool.cs} (88%) diff --git a/DigitalData.Core.Abstractions/Security/IAsymmetricKeyFactory.cs b/DigitalData.Core.Abstractions/Security/IAsymmetricKeyFactory.cs index 76caa12..31b8bdb 100644 --- a/DigitalData.Core.Abstractions/Security/IAsymmetricKeyFactory.cs +++ b/DigitalData.Core.Abstractions/Security/IAsymmetricKeyFactory.cs @@ -1,23 +1,22 @@ using System.Security.Cryptography; -namespace DigitalData.Core.Abstractions.Security +namespace DigitalData.Core.Abstractions.Security; + +public interface IAsymmetricKeyFactory { - public interface IAsymmetricKeyFactory - { - string CreatePrivateKeyPem(int? keySizeInBits = null, bool encrypt = false); + string CreatePrivateKeyPem(int? keySizeInBits = null, bool encrypt = false); - string CreateEncryptedPrivateKeyPem( - PbeEncryptionAlgorithm? pbeEncryptionAlgorithm = null, - HashAlgorithmName? hashAlgorithmName = null, - int? iterationCount = null, - int? keySizeInBits = null, - string? password = null); + string CreateEncryptedPrivateKeyPem( + PbeEncryptionAlgorithm? pbeEncryptionAlgorithm = null, + HashAlgorithmName? hashAlgorithmName = null, + int? iterationCount = null, + int? keySizeInBits = null, + string? password = null); - string CreateEncryptedPrivateKeyPem( - PbeParameters pbeParameters, - int? keySizeInBits = null, - string? password = null); + string CreateEncryptedPrivateKeyPem( + PbeParameters pbeParameters, + int? keySizeInBits = null, + string? password = null); - IAsymmetricDecryptor CreateDecryptor(string pem, string? issuer = null, string? audience = null, bool encrypt = false, RSAEncryptionPadding? padding = null); - } + IAsymmetricDecryptor CreateDecryptor(string pem, string? issuer = null, string? audience = null, bool encrypt = false, RSAEncryptionPadding? padding = null); } \ No newline at end of file diff --git a/DigitalData.Core.Abstractions/Security/IAsymmetricKeyPool.cs b/DigitalData.Core.Abstractions/Security/IAsymmetricKeyPool.cs new file mode 100644 index 0000000..ffc9da3 --- /dev/null +++ b/DigitalData.Core.Abstractions/Security/IAsymmetricKeyPool.cs @@ -0,0 +1,10 @@ +namespace DigitalData.Core.Abstractions.Security; + +public interface IAsymmetricKeyPool : IAsymmetricKeyFactory +{ + IEnumerable Decryptors { get; } + + IAsymmetricDecryptor VaultDecryptor { get; } + + IEnumerable TokenDescriptors { get; } +} \ No newline at end of file diff --git a/DigitalData.Core.Abstractions/Security/ICryptoFactory.cs b/DigitalData.Core.Abstractions/Security/ICryptoFactory.cs deleted file mode 100644 index 180d8d6..0000000 --- a/DigitalData.Core.Abstractions/Security/ICryptoFactory.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace DigitalData.Core.Abstractions.Security -{ - public interface ICryptoFactory : IAsymmetricKeyFactory - { - IEnumerable Decryptors { get; } - - IAsymmetricDecryptor VaultDecryptor { get; } - - IEnumerable TokenDescriptors { get; } - } -} \ No newline at end of file diff --git a/DigitalData.Core.Security/DIExtensions.cs b/DigitalData.Core.Security/DIExtensions.cs index 4d86c90..f16bf3e 100644 --- a/DigitalData.Core.Security/DIExtensions.cs +++ b/DigitalData.Core.Security/DIExtensions.cs @@ -19,7 +19,7 @@ namespace DigitalData.Core.Security public static IServiceCollection AddCryptoFactory(this IServiceCollection services, IConfiguration configuration) => services .Configure(configuration) .AddAutoMapper(typeof(MappingProfile).Assembly) - .AddSingleton() + .AddSingleton() .AddSingleton() .AddHostedService(); diff --git a/DigitalData.Core.Security/Services/JwtSignatureHandler.cs b/DigitalData.Core.Security/Services/JwtSignatureHandler.cs index 64fd018..71c0a17 100644 --- a/DigitalData.Core.Security/Services/JwtSignatureHandler.cs +++ b/DigitalData.Core.Security/Services/JwtSignatureHandler.cs @@ -13,9 +13,9 @@ public class JwtSignatureHandler : JwtSecurityTokenHandler, IJwtSign private readonly IMapper _mapper; - private readonly ICryptoFactory _cryptoFactory; + private readonly IAsymmetricKeyPool _cryptoFactory; - public JwtSignatureHandler(IOptions> claimDescriptorOptions, IMapper mapper, ICryptoFactory cryptoFactory) + public JwtSignatureHandler(IOptions> claimDescriptorOptions, IMapper mapper, IAsymmetricKeyPool cryptoFactory) { _claimDescriptor = claimDescriptorOptions.Value; _mapper = mapper; diff --git a/DigitalData.Core.Security/Services/CryptoFactory.cs b/DigitalData.Core.Security/Services/RSAPool.cs similarity index 88% rename from DigitalData.Core.Security/Services/CryptoFactory.cs rename to DigitalData.Core.Security/Services/RSAPool.cs index 4596968..29b90e1 100644 --- a/DigitalData.Core.Security/Services/CryptoFactory.cs +++ b/DigitalData.Core.Security/Services/RSAPool.cs @@ -5,7 +5,7 @@ using Microsoft.Extensions.Options; namespace DigitalData.Core.Security.Services; -public class CryptoFactory : RSAFactory, ICryptoFactory, IAsymmetricKeyFactory +public class RSAPool : RSAFactory, IAsymmetricKeyPool, IAsymmetricKeyFactory { private readonly CryptoFactoryParams _params; @@ -18,7 +18,7 @@ public class CryptoFactory : RSAFactory, ICryptoFactory, IAsymmetricKeyFactory public IEnumerable TokenDescriptors { get; init; } = new List(); - public CryptoFactory(IOptions cryptoFactoryParamsOptions, ILogger? logger = null) + public RSAPool(IOptions cryptoFactoryParamsOptions, ILogger? logger = null) { _params = cryptoFactoryParamsOptions.Value;