diff --git a/DigitalData.Core.Security/AsymCryptService.cs b/DigitalData.Core.Security/AsymCryptService.cs index c6ff3cf..cc471af 100644 --- a/DigitalData.Core.Security/AsymCryptService.cs +++ b/DigitalData.Core.Security/AsymCryptService.cs @@ -12,6 +12,20 @@ namespace DigitalData.Core.Security { public IEnumerable Decryptors => _params.Decryptors; + public IRSADecryptor this[string key] + { + get + { + var key_params = key.Split(_params.KeyNameSeparator); + + if (key_params.Length != 2) + throw new ArgumentException($"Invalid key format. Expected two segments separated by '{_params.KeyNameSeparator}', but received: '{key}'.", nameof(key)); + + return _params.Decryptors.FirstOrDefault(d => d.Issuer == key_params[0] && d.Audience == key_params[1]) + ?? throw new KeyNotFoundException($"No decryptor found matching the issuer '{key_params[0]}' and audience '{key_params[1]}'."); + } + } + public AsymCryptService(IOptions options, ILogger>? logger = null) : base(options) { logger?.LogInformation("Core.Secrets version: {Version}, Created on: {CreationDate}.", Secrets.Version, Secrets.CreationDate.ToString("dd.MM.yyyy")); diff --git a/DigitalData.Core.Security/Config/AsymCryptParams.cs b/DigitalData.Core.Security/Config/AsymCryptParams.cs index c6cc565..2108183 100644 --- a/DigitalData.Core.Security/Config/AsymCryptParams.cs +++ b/DigitalData.Core.Security/Config/AsymCryptParams.cs @@ -53,7 +53,7 @@ namespace DigitalData.Core.Security.Config if (decryptor.IsEncrypted) file_name_params.Add(Secrets.Version); - var path = Path.Combine(PemDirectory, string.Join(Separator, file_name_params)); + var path = Path.Combine(PemDirectory, string.Join(FileNameSeparator, file_name_params)); if (File.Exists(path)) decryptor.SetPem(File.ReadAllText(path));