refactor(TokenDescription): Nach RSAKey verschoben, um unter RSAPrivateKey definiert werden zu können

This commit is contained in:
Developer 02
2025-01-07 13:22:45 +01:00
parent b5cecac745
commit 09a31b5a3d
8 changed files with 31 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
using DigitalData.Core.Abstractions.Security;
using DigitalData.Core.Security.Config;
using Microsoft.IdentityModel.Tokens;
using System.Security.Cryptography;
@@ -28,6 +29,12 @@ namespace DigitalData.Core.Security.RSAKey
public IAsymmetricPublicKey PublicKey => _lazyPublicKey.Value;
private RSATokenDescriptor? _tokenDescriptor;
private readonly Lazy<RSATokenDescriptor?> _descLazyInitter;
public RSATokenDescriptor? TokenDescriptor { get => _descLazyInitter.Value; init => _tokenDescriptor = value; }
public RSAPrivateKey()
{
_lazyPublicKey = new(() => new RSAPublicKey()
@@ -35,6 +42,17 @@ namespace DigitalData.Core.Security.RSAKey
Pem = RSA.ExportRSAPublicKeyPem(),
Padding = Padding
});
_descLazyInitter = new(() =>
{
if(_tokenDescriptor is not null)
{
_tokenDescriptor.Issuer = Issuer;
_tokenDescriptor.Audience = Audience;
_tokenDescriptor.SigningCredentials = CreateSigningCredentials();
}
return _tokenDescriptor;
});
}
public byte[] Decrypt(byte[] data) => RSA.Decrypt(data, Padding);