refactor(RSACryptographer): Verfallsdatum und Version entfernt
This commit is contained in:
parent
c9548238bb
commit
506685a0b5
@ -1,6 +1,5 @@
|
||||
using DigitalData.Core.Abstractions.Security;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace DigitalData.Core.Security
|
||||
{
|
||||
@ -16,35 +15,6 @@ namespace DigitalData.Core.Security
|
||||
|
||||
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() { }
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using DigitalData.Core.Abstractions.Security;
|
||||
using DigitalData.Core.Security.DigitalData.Core.Security;
|
||||
using DigitalData.Core.Security.Extensions;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
@ -31,6 +32,8 @@ namespace DigitalData.Core.Security
|
||||
|
||||
protected override RSA RSA => lazyRSA.Value;
|
||||
|
||||
public override CryptKeyType KeyType => IsEncrypted ? CryptKeyType.EncryptedPrivate : CryptKeyType.Private;
|
||||
|
||||
public RSADecryptor()
|
||||
{
|
||||
_lazyEncryptor = new(() => new RSAEncryptor()
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using DigitalData.Core.Abstractions.Security;
|
||||
using DigitalData.Core.Security.DigitalData.Core.Security;
|
||||
using DigitalData.Core.Security.Extensions;
|
||||
|
||||
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 string Encrypt(string data) => RSA.Encrypt(data.Base64ToByte(), Padding).BytesToString();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user