refactor(AsymCryptParams): Unnötige Methoden entfernt
This commit is contained in:
parent
a9ebc406f3
commit
7ec85b4e30
@ -6,19 +6,22 @@ namespace DigitalData.Core.Security.Config
|
|||||||
{
|
{
|
||||||
public string PemDirectory { get; init; } = string.Empty;
|
public string PemDirectory { get; init; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the separator used to concatenate the components of a token string.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The resulting token string is constructed as follows:
|
||||||
|
/// <c>string.Join(Separator, Issuer, Audience, Secret_version)</c>.
|
||||||
|
/// If <c>Secret_version</c> is not null, it will be included in the concatenation.
|
||||||
|
/// </remarks>
|
||||||
|
/// <example>
|
||||||
|
/// For example, if <c>Separator = "_-_"</c>, the output might look like:
|
||||||
|
/// <c>"Issuer_-_Audience_-_Secret_version"</c>.
|
||||||
|
/// </example>
|
||||||
public string Separator { get; init; } = "_-_";
|
public string Separator { get; init; } = "_-_";
|
||||||
|
|
||||||
public IEnumerable<RSADecryptor> Decryptors { get; init; } = new List<RSADecryptor>();
|
public IEnumerable<RSADecryptor> Decryptors { get; init; } = new List<RSADecryptor>();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 0: Issuer - 1: Audience - 2: Secret version (if is encrypted)
|
|
||||||
/// </summary>
|
|
||||||
private string CreateFileName(params object[] objs) => string.Join(Separator, objs);
|
|
||||||
|
|
||||||
private string CreatePem(bool isEncrypted) => isEncrypted
|
|
||||||
? Instance.RSAFactory.CreateEncryptedPrivateKeyPem(pbeParameters: PbeParameters, keySizeInBits: KeySizeInBits, password: Secrets.PBE_PASSWORD)
|
|
||||||
: Instance.RSAFactory.CreatePrivateKeyPem(keySizeInBits: KeySizeInBits);
|
|
||||||
|
|
||||||
public override void OnDeserialized()
|
public override void OnDeserialized()
|
||||||
{
|
{
|
||||||
base.OnDeserialized();
|
base.OnDeserialized();
|
||||||
@ -36,15 +39,19 @@ namespace DigitalData.Core.Security.Config
|
|||||||
if (crypt.Encrypt)
|
if (crypt.Encrypt)
|
||||||
file_name_params.Add(Secrets.Version);
|
file_name_params.Add(Secrets.Version);
|
||||||
|
|
||||||
var file_name = CreateFileName(file_name_params);
|
var path = Path.Combine(PemDirectory, string.Join(Separator, file_name_params));
|
||||||
var path = Path.Combine(PemDirectory, file_name);
|
|
||||||
|
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
crypt.SetPem(File.ReadAllText(path));
|
crypt.SetPem(File.ReadAllText(path));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var pem = CreatePem(crypt.Encrypt);
|
var pem = crypt.Encrypt
|
||||||
|
? Instance.RSAFactory.CreateEncryptedPrivateKeyPem(pbeParameters: PbeParameters, keySizeInBits: KeySizeInBits, password: Secrets.PBE_PASSWORD)
|
||||||
|
: Instance.RSAFactory.CreatePrivateKeyPem(keySizeInBits: KeySizeInBits);
|
||||||
|
|
||||||
crypt.SetPem(File.ReadAllText(pem));
|
crypt.SetPem(File.ReadAllText(pem));
|
||||||
|
|
||||||
|
// Save file in background
|
||||||
Task.Run(async () => await File.WriteAllTextAsync(path: path, pem));
|
Task.Run(async () => await File.WriteAllTextAsync(path: path, pem));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user