refactor(RSACryptographer): Verfallsdatum und Version entfernt

This commit is contained in:
Developer 02 2024-12-05 09:17:44 +01:00
parent c9548238bb
commit 506685a0b5
3 changed files with 7 additions and 31 deletions

View File

@ -1,6 +1,5 @@
using DigitalData.Core.Abstractions.Security; using DigitalData.Core.Abstractions.Security;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text.Json;
namespace DigitalData.Core.Security namespace DigitalData.Core.Security
{ {
@ -16,35 +15,6 @@ namespace DigitalData.Core.Security
public string? Audience { get; init; } public string? Audience { get; init; }
private DateOnly? _expiration;
public DateOnly? Expiration
{
get => _expiration;
init
{
if (value <= DateOnly.FromDateTime(DateTime.Now))
throw new InvalidOperationException($"Cryptographer expiration date has already passed. Cryptographer: {JsonSerializer.Serialize(this)}");
_expiration = value;
}
}
private Version? _version;
public Version? Version
{
get => _version;
init
{
if (value != Secrets.Version)
throw new InvalidOperationException($"Cryptographer version ({value}) does not match the expected version ({Secrets.Version}). Cryptographer: {JsonSerializer.Serialize(this)}");
_version = value;
}
}
internal RSACryptographer() { } internal RSACryptographer() { }
} }
} }

View File

@ -1,4 +1,5 @@
using DigitalData.Core.Abstractions.Security; using DigitalData.Core.Abstractions.Security;
using DigitalData.Core.Security.DigitalData.Core.Security;
using DigitalData.Core.Security.Extensions; using DigitalData.Core.Security.Extensions;
using System.Security.Cryptography; using System.Security.Cryptography;
@ -31,6 +32,8 @@ namespace DigitalData.Core.Security
protected override RSA RSA => lazyRSA.Value; protected override RSA RSA => lazyRSA.Value;
public override CryptKeyType KeyType => IsEncrypted ? CryptKeyType.EncryptedPrivate : CryptKeyType.Private;
public RSADecryptor() public RSADecryptor()
{ {
_lazyEncryptor = new(() => new RSAEncryptor() _lazyEncryptor = new(() => new RSAEncryptor()

View File

@ -1,4 +1,5 @@
using DigitalData.Core.Abstractions.Security; using DigitalData.Core.Abstractions.Security;
using DigitalData.Core.Security.DigitalData.Core.Security;
using DigitalData.Core.Security.Extensions; using DigitalData.Core.Security.Extensions;
namespace DigitalData.Core.Security namespace DigitalData.Core.Security
@ -15,6 +16,8 @@ namespace DigitalData.Core.Security
} }
} }
public override CryptKeyType KeyType => CryptKeyType.Public;
public byte[] Encrypt(byte[] data) => RSA.Encrypt(data, Padding); public byte[] Encrypt(byte[] data) => RSA.Encrypt(data, Padding);
public string Encrypt(string data) => RSA.Encrypt(data.Base64ToByte(), Padding).BytesToString(); public string Encrypt(string data) => RSA.Encrypt(data.Base64ToByte(), Padding).BytesToString();