using DigitalData.Core.Abstractions.Security; using System.Security.Cryptography; namespace DigitalData.Core.Security.Cryptographer { public class RSACryptographer : IRSACryptographer { protected string? _pem; public string Pem { get => _pem ?? throw PemIsNullException; init => _pem = value; } internal bool IsPemNull => _pem is null; private InvalidOperationException PemIsNullException => new($"Pem is not initialized. Please ensure that the PEM is set or properly loaded from the file. Issuer: {Issuer}, Audience: {Audience}."); public RSAEncryptionPadding Padding { get; init; } = RSAEncryptionPadding.OaepSHA256; protected virtual RSA RSA { get; } = RSA.Create(); public string Issuer { get; init; } = string.Empty; public string Audience { get; init; } = string.Empty; internal RSACryptographer() { } internal void SetPem(string pem) => _pem = pem; public virtual void Init() { if (_pem is null) throw PemIsNullException; } } }