Developer 02 76ce64691a refactor(RSACryptographer): Verzeichnis und Dateiname wurden entfernt.
- Datei-Leseprozess in init-Methode entfernt.
2024-12-13 10:29:49 +01:00

39 lines
1.1 KiB
C#

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;
}
}
}