diff --git a/DigitalData.Core.Security/DIExtensions.cs b/DigitalData.Core.Security/DIExtensions.cs index 7e05dd3..8263afd 100644 --- a/DigitalData.Core.Security/DIExtensions.cs +++ b/DigitalData.Core.Security/DIExtensions.cs @@ -21,6 +21,7 @@ namespace DigitalData.Core.Security .Configure(configuration) .AddAutoMapper(typeof(MappingProfile).Assembly) .AddSingleton() + .AddSingleton() .AddHostedService(); public static IServiceCollection AddJwtSignatureHandler(this IServiceCollection services, diff --git a/DigitalData.Core.Security/Instance.cs b/DigitalData.Core.Security/Instance.cs deleted file mode 100644 index d372ab0..0000000 --- a/DigitalData.Core.Security/Instance.cs +++ /dev/null @@ -1,14 +0,0 @@ -using DigitalData.Core.Abstractions.Security; -using DigitalData.Core.Security.Config; -using DigitalData.Core.Security.RSAKey; -using Microsoft.Extensions.Options; - -namespace DigitalData.Core.Security -{ - public static class Instance - { - private static readonly Lazy> LazyInstance = new(() => new(Options.Create(new()))); - - public static IAsymmetricKeyFactory RSAFactory => LazyInstance.Value; - } -} \ No newline at end of file diff --git a/DigitalData.Core.Security/RSAKey/RSAFactory.cs b/DigitalData.Core.Security/RSAKey/RSAFactory.cs index 6acbc95..ebf3490 100644 --- a/DigitalData.Core.Security/RSAKey/RSAFactory.cs +++ b/DigitalData.Core.Security/RSAKey/RSAFactory.cs @@ -6,6 +6,8 @@ namespace DigitalData.Core.Security.RSAKey; public class RSAFactory : IAsymmetricKeyFactory { + public static readonly RSAFactory Static = new(); + public string CreatePrivateKeyPem(int? keySizeInBits = null, bool encrypt = false) => encrypt ? CreateEncryptedPrivateKeyPem(keySizeInBits: keySizeInBits) : RSA.Create(keySizeInBits ?? RSAFactoryParams.Default.KeySizeInBits).ExportRSAPrivateKeyPem(); diff --git a/DigitalData.Core.Security/Services/PemFileInitalizer.cs b/DigitalData.Core.Security/Services/PemFileInitalizer.cs index 4b65d3d..98f062b 100644 --- a/DigitalData.Core.Security/Services/PemFileInitalizer.cs +++ b/DigitalData.Core.Security/Services/PemFileInitalizer.cs @@ -70,8 +70,8 @@ public class PemFileInitalizer : BackgroundService else { var pem = privateKey.IsEncrypted - ? Instance.RSAFactory.CreateEncryptedPrivateKeyPem(pbeParameters: _factoryParams.PbeParameters, keySizeInBits: _factoryParams.KeySizeInBits, password: Secrets.PBE_PASSWORD) - : Instance.RSAFactory.CreatePrivateKeyPem(keySizeInBits: _factoryParams.KeySizeInBits); + ? RSAFactory.Static.CreateEncryptedPrivateKeyPem(pbeParameters: _factoryParams.PbeParameters, keySizeInBits: _factoryParams.KeySizeInBits, password: Secrets.PBE_PASSWORD) + : RSAFactory.Static.CreatePrivateKeyPem(keySizeInBits: _factoryParams.KeySizeInBits); privateKey.SetPem(pem);