diff --git a/DigitalData.Core.Security/RSACryptographer.cs b/DigitalData.Core.Security/RSACryptographer.cs index ba316ee..1b357bd 100644 --- a/DigitalData.Core.Security/RSACryptographer.cs +++ b/DigitalData.Core.Security/RSACryptographer.cs @@ -1,6 +1,5 @@ using DigitalData.Core.Abstractions.Security; using System.Security.Cryptography; -using System.Text.Json; namespace DigitalData.Core.Security { @@ -15,36 +14,7 @@ namespace DigitalData.Core.Security public string? Issuer { 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() { } } } \ No newline at end of file diff --git a/DigitalData.Core.Security/RSADecryptor.cs b/DigitalData.Core.Security/RSADecryptor.cs index a527fe5..60bfc71 100644 --- a/DigitalData.Core.Security/RSADecryptor.cs +++ b/DigitalData.Core.Security/RSADecryptor.cs @@ -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() diff --git a/DigitalData.Core.Security/RSAEncryptor.cs b/DigitalData.Core.Security/RSAEncryptor.cs index 7783902..36e6177 100644 --- a/DigitalData.Core.Security/RSAEncryptor.cs +++ b/DigitalData.Core.Security/RSAEncryptor.cs @@ -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();