refactor(RSADecryptor): aktualisiert, um im Passwort- und Versions-Tupel-Format zu initieren, um Datenintegrität zu gewährleisten.

- password und PasswordVersion initter entfernt.
This commit is contained in:
Developer 02 2024-11-20 12:49:36 +01:00
parent 103ddf5c2e
commit 6ab1777f7c
2 changed files with 17 additions and 8 deletions

View File

@ -2,9 +2,9 @@
{
public interface IRSADecryptor : IRSACryptographer
{
string? Password { init; }
(string Value, Version Version) VersionedPassword { init; }
Version? PasswordVersion { get; init; }
Version? PasswordVersion { get; }
bool HasEncryptedPem { get; }

View File

@ -6,13 +6,22 @@ namespace DigitalData.Core.Security
{
public class RSADecryptor : RSACryptographer, IRSADecryptor, IRSACryptographer
{
public string? Password { internal get; init; }
public (string Value, Version Version) VersionedPassword
{
init
{
_password = value.Value;
PasswordVersion = value.Version;
}
}
public Version? PasswordVersion { get; init; }
private string? _password;
public bool HasEncryptedPem => Password is not null;
public Version? PasswordVersion { get; private init; }
public bool IsEncrypted => Password is not null;
public bool HasEncryptedPem => _password is not null;
public bool IsEncrypted => _password is not null;
private readonly Lazy<IRSAEncryptor> _lazyEncryptor;
@ -33,10 +42,10 @@ namespace DigitalData.Core.Security
lazyRSA = new(() =>
{
var rsa = RSA.Create();
if (Password is null)
if (_password is null)
RSA.ImportFromPem(Pem);
else
RSA.ImportFromEncryptedPem(Pem, Password.AsSpan());
RSA.ImportFromEncryptedPem(Pem, _password.AsSpan());
return rsa;
});