refactor(RSACryptographer): Entfernen von _pem, IsPemNull, SetPem, Init und Methoden zur Vereinfachung von RSAEncryptor

This commit is contained in:
Developer 02
2024-12-13 16:17:35 +01:00
parent fe2ee78d14
commit 68ef0a7537
4 changed files with 29 additions and 32 deletions

View File

@@ -5,19 +5,8 @@ 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 virtual string Pem { get; init; }
public RSAEncryptionPadding Padding { get; init; } = RSAEncryptionPadding.OaepSHA256;
protected virtual RSA RSA { get; } = RSA.Create();
@@ -26,14 +15,8 @@ namespace DigitalData.Core.Security.Cryptographer
public string Audience { get; init; } = string.Empty;
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
internal RSACryptographer() { }
internal void SetPem(string pem) => _pem = pem;
public virtual void Init()
{
if (_pem is null)
throw PemIsNullException;
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
}
}