Developer 02 144fe86987 refactor(CryptoFactoryParams): PemFileInitalizer erstellt, um das Lesen und Aktualisieren von Pem-Dateien zu ermöglichen.
- Minimierung der di-Erweiterungsmethoden.
 - AfterCreate-Methode entfernt
2025-03-13 17:10:22 +01:00

40 lines
1.4 KiB
C#

using System.Reflection;
using System.Security.Cryptography;
using System.Text.Json.Serialization;
namespace DigitalData.Core.Security.Config
{
public class RSAFactoryParams
{
public int KeySizeInBits { get; init; } = 2048;
public string PbePassword { internal get; init; } = Secrets.PBE_PASSWORD;
public PbeEncryptionAlgorithm PbeEncryptionAlgorithm { get; init; } = PbeEncryptionAlgorithm.Aes256Cbc;
public HashAlgorithmName PbeHashAlgorithm { get; init; } = HashAlgorithmName.SHA256;
// TODO: add as json converter to IConfigurIConfiguration.Config
public string PbeHashAlgorithmName
{
get => PbeHashAlgorithm.ToString();
init => PbeHashAlgorithm = (typeof(HashAlgorithmName).GetProperty(value, BindingFlags.Public | BindingFlags.Static)?.GetValue(null) is HashAlgorithmName hashAlgorithmName)
? hashAlgorithmName
: new(value);
}
public int PbeIterationCount { get; init; } = 100_000;
public string EncryptedPrivateKeyPemLabel { get; init; } = "ENCRYPTED PRIVATE KEY";
private readonly Lazy<PbeParameters> _lazyPbeParameters;
[JsonIgnore]
public PbeParameters PbeParameters => _lazyPbeParameters.Value;
public RSAFactoryParams()
{
_lazyPbeParameters = new(() => new PbeParameters(PbeEncryptionAlgorithm, PbeHashAlgorithm, PbeIterationCount));
}
}
}