refactor(RSAFactoryParams): Eigenschaft PbeParameters hinzugefügt
This commit is contained in:
parent
c895d2df0e
commit
65989b23b3
@ -13,10 +13,10 @@ namespace DigitalData.Core.Security.Extensions
|
||||
return rsa;
|
||||
}
|
||||
|
||||
public static IRSADecryptor GetRSADecryptor(this IAsymCryptService factory, string issuer, string audience, Version? version = null, string? seperator = null)
|
||||
public static IRSADecryptor GetRSADecryptor<TParams>(this IAsymCryptService<TParams> factory, string issuer, string audience, Version? version = null, string? seperator = null)
|
||||
=> factory[factory.RSAKeyNameFormatter(issuer, audience, true, version, seperator)];
|
||||
|
||||
public static bool TryGetRSADecryptor(this IAsymCryptService factory, string issuer, string audience, out IRSADecryptor? decryptor, Version? version = null, string? seperator = null)
|
||||
public static bool TryGetRSADecryptor<TParams>(this IAsymCryptService<TParams> factory, string issuer, string audience, out IRSADecryptor? decryptor, Version? version = null, string? seperator = null)
|
||||
=> factory.TryGetRSADecryptor(factory.RSAKeyNameFormatter(issuer, audience, true, version, seperator), out decryptor);
|
||||
|
||||
private static string CreatePath(string filename, string? directory = null)
|
||||
|
||||
@ -12,13 +12,7 @@ namespace DigitalData.Core.Security
|
||||
|
||||
protected readonly TRSAFactoryParams _params;
|
||||
|
||||
private readonly PbeParameters _pbeParameters;
|
||||
|
||||
public RSAFactory(IOptions<TRSAFactoryParams> options)
|
||||
{
|
||||
_params = options.Value;
|
||||
_pbeParameters = new PbeParameters(_params.PbeEncryptionAlgorithm, _params.PbeHashAlgorithmName, _params.PbeIterationCount);
|
||||
}
|
||||
public RSAFactory(IOptions<TRSAFactoryParams> options) => _params = options.Value;
|
||||
|
||||
public string CreateRSAPrivateKeyPem(int? keySizeInBits = null)
|
||||
=> RSA.Create(keySizeInBits ?? _params.KeySizeInBits).ExportRSAPrivateKeyPem();
|
||||
@ -37,7 +31,7 @@ namespace DigitalData.Core.Security
|
||||
pbeEncryptionAlgorithm ?? _params.PbeEncryptionAlgorithm,
|
||||
hashAlgorithmName ?? _params.PbeHashAlgorithmName,
|
||||
iterationCount ?? _params.PbeIterationCount)
|
||||
: _pbeParameters;
|
||||
: _params.PbeParameters;
|
||||
|
||||
var encryptedPrivateKey = RSA.Create(keySizeInBits ?? _params.KeySizeInBits).ExportEncryptedPkcs8PrivateKey(password.AsSpan(), pbeParameters);
|
||||
|
||||
|
||||
@ -23,5 +23,12 @@ namespace DigitalData.Core.Security
|
||||
public int PbeIterationCount { get; init; } = 100_000;
|
||||
|
||||
public string EncryptedPrivateKeyPemLabel { get; init; } = "ENCRYPTED PRIVATE KEY";
|
||||
|
||||
private readonly Lazy<PbeParameters> _lazyPbeParameters;
|
||||
|
||||
public PbeParameters PbeParameters => _lazyPbeParameters.Value;
|
||||
|
||||
public RSAFactoryParams()
|
||||
=> _lazyPbeParameters = new(() => new PbeParameters(PbeEncryptionAlgorithm, PbeHashAlgorithmName, PbeIterationCount));
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user