refactor(Instance): removed.
- Moved statc RSAFactory instance to RSAFactory
This commit is contained in:
@@ -21,6 +21,7 @@ namespace DigitalData.Core.Security
|
|||||||
.Configure<CryptoFactoryParams>(configuration)
|
.Configure<CryptoFactoryParams>(configuration)
|
||||||
.AddAutoMapper(typeof(MappingProfile).Assembly)
|
.AddAutoMapper(typeof(MappingProfile).Assembly)
|
||||||
.AddSingleton<ICryptoFactory, CryptoFactory>()
|
.AddSingleton<ICryptoFactory, CryptoFactory>()
|
||||||
|
.AddSingleton<IAsymmetricKeyFactory, RSAFactory>()
|
||||||
.AddHostedService<PemFileInitalizer>();
|
.AddHostedService<PemFileInitalizer>();
|
||||||
|
|
||||||
public static IServiceCollection AddJwtSignatureHandler<TPrincipal>(this IServiceCollection services,
|
public static IServiceCollection AddJwtSignatureHandler<TPrincipal>(this IServiceCollection services,
|
||||||
|
|||||||
@@ -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<RSAFactory<RSAFactoryParams>> LazyInstance = new(() => new(Options.Create<RSAFactoryParams>(new())));
|
|
||||||
|
|
||||||
public static IAsymmetricKeyFactory RSAFactory => LazyInstance.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,8 @@ namespace DigitalData.Core.Security.RSAKey;
|
|||||||
|
|
||||||
public class RSAFactory : IAsymmetricKeyFactory
|
public class RSAFactory : IAsymmetricKeyFactory
|
||||||
{
|
{
|
||||||
|
public static readonly RSAFactory Static = new();
|
||||||
|
|
||||||
public string CreatePrivateKeyPem(int? keySizeInBits = null, bool encrypt = false) => encrypt
|
public string CreatePrivateKeyPem(int? keySizeInBits = null, bool encrypt = false) => encrypt
|
||||||
? CreateEncryptedPrivateKeyPem(keySizeInBits: keySizeInBits)
|
? CreateEncryptedPrivateKeyPem(keySizeInBits: keySizeInBits)
|
||||||
: RSA.Create(keySizeInBits ?? RSAFactoryParams.Default.KeySizeInBits).ExportRSAPrivateKeyPem();
|
: RSA.Create(keySizeInBits ?? RSAFactoryParams.Default.KeySizeInBits).ExportRSAPrivateKeyPem();
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ public class PemFileInitalizer : BackgroundService
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var pem = privateKey.IsEncrypted
|
var pem = privateKey.IsEncrypted
|
||||||
? Instance.RSAFactory.CreateEncryptedPrivateKeyPem(pbeParameters: _factoryParams.PbeParameters, keySizeInBits: _factoryParams.KeySizeInBits, password: Secrets.PBE_PASSWORD)
|
? RSAFactory.Static.CreateEncryptedPrivateKeyPem(pbeParameters: _factoryParams.PbeParameters, keySizeInBits: _factoryParams.KeySizeInBits, password: Secrets.PBE_PASSWORD)
|
||||||
: Instance.RSAFactory.CreatePrivateKeyPem(keySizeInBits: _factoryParams.KeySizeInBits);
|
: RSAFactory.Static.CreatePrivateKeyPem(keySizeInBits: _factoryParams.KeySizeInBits);
|
||||||
|
|
||||||
privateKey.SetPem(pem);
|
privateKey.SetPem(pem);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user