diff --git a/DigitalData.Core.Security/Config/AsymCryptParams.cs b/DigitalData.Core.Security/Config/AsymCryptParams.cs
index a2a2a24..e991cc1 100644
--- a/DigitalData.Core.Security/Config/AsymCryptParams.cs
+++ b/DigitalData.Core.Security/Config/AsymCryptParams.cs
@@ -6,19 +6,22 @@ namespace DigitalData.Core.Security.Config
{
public string PemDirectory { get; init; } = string.Empty;
+ ///
+ /// Represents the separator used to concatenate the components of a token string.
+ ///
+ ///
+ /// The resulting token string is constructed as follows:
+ /// string.Join(Separator, Issuer, Audience, Secret_version).
+ /// If Secret_version is not null, it will be included in the concatenation.
+ ///
+ ///
+ /// For example, if Separator = "_-_", the output might look like:
+ /// "Issuer_-_Audience_-_Secret_version".
+ ///
public string Separator { get; init; } = "_-_";
public IEnumerable Decryptors { get; init; } = new List();
- ///
- /// 0: Issuer - 1: Audience - 2: Secret version (if is encrypted)
- ///
- 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()
{
base.OnDeserialized();
@@ -36,15 +39,19 @@ namespace DigitalData.Core.Security.Config
if (crypt.Encrypt)
file_name_params.Add(Secrets.Version);
- var file_name = CreateFileName(file_name_params);
- var path = Path.Combine(PemDirectory, file_name);
+ var path = Path.Combine(PemDirectory, string.Join(Separator, file_name_params));
if (File.Exists(path))
crypt.SetPem(File.ReadAllText(path));
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));
+
+ // Save file in background
Task.Run(async () => await File.WriteAllTextAsync(path: path, pem));
}
}