From 6ab1777f7c2dec809d47404f60b455e723fd4721 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Wed, 20 Nov 2024 12:49:36 +0100 Subject: [PATCH] =?UTF-8?q?refactor(RSADecryptor):=20aktualisiert,=20um=20?= =?UTF-8?q?im=20Passwort-=20und=20Versions-Tupel-Format=20zu=20initieren,?= =?UTF-8?q?=20um=20Datenintegrit=C3=A4t=20zu=20gew=C3=A4hrleisten.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - password und PasswordVersion initter entfernt. --- .../Security/IRSADecryptor.cs | 4 ++-- DigitalData.Core.Security/RSADecryptor.cs | 21 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/DigitalData.Core.Abstractions/Security/IRSADecryptor.cs b/DigitalData.Core.Abstractions/Security/IRSADecryptor.cs index 2600394..91a906b 100644 --- a/DigitalData.Core.Abstractions/Security/IRSADecryptor.cs +++ b/DigitalData.Core.Abstractions/Security/IRSADecryptor.cs @@ -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; } diff --git a/DigitalData.Core.Security/RSADecryptor.cs b/DigitalData.Core.Security/RSADecryptor.cs index 244ef17..4c23da2 100644 --- a/DigitalData.Core.Security/RSADecryptor.cs +++ b/DigitalData.Core.Security/RSADecryptor.cs @@ -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; + } + } + + private string? _password; - public Version? PasswordVersion { get; init; } + public Version? PasswordVersion { get; private init; } - public bool HasEncryptedPem => Password is not null; + public bool HasEncryptedPem => _password is not null; - public bool IsEncrypted => Password is not null; + public bool IsEncrypted => _password is not null; private readonly Lazy _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; });