27 lines
1.2 KiB
C#
27 lines
1.2 KiB
C#
using DigitalData.Core.Abstractions.Security;
|
|
using DigitalData.Core.Security.Config;
|
|
using DigitalData.Core.Security.Cryptographer;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace DigitalData.Core.Security
|
|
{
|
|
public class AsymCryptService<TAsymCryptParams> : RSAFactory<TAsymCryptParams>, IAsymCryptService<TAsymCryptParams>, IRSAFactory<TAsymCryptParams> where TAsymCryptParams : AsymCryptParams
|
|
{
|
|
public IEnumerable<IRSADecryptor> Decryptors => _params.Decryptors;
|
|
|
|
public IEnumerable<IRSAEncryptor> Encryptors => _params.Encryptors;
|
|
|
|
private readonly Dictionary<string, IRSADecryptor> _decryptors;
|
|
|
|
public IRSADecryptor this[string key] { get => _decryptors[key]; set => _decryptors[key] = value; }
|
|
|
|
public AsymCryptService(IOptions<TAsymCryptParams> options, ILogger<AsymCryptService<TAsymCryptParams>>? logger = null) : base(options)
|
|
{
|
|
_decryptors = new();
|
|
logger?.LogInformation("Core.Secrets version: {Version}, Created on: {CreationDate}.", Secrets.Version, Secrets.CreationDate.ToString("dd.MM.yyyy"));
|
|
}
|
|
|
|
public bool TryGetRSADecryptor(string key, out IRSADecryptor? decryptor) => _decryptors.TryGetValue(key, out decryptor);
|
|
}
|
|
} |