From f28b43cc066b204fa6e0eb706686fb3eae63c010 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Tue, 19 Nov 2024 23:58:04 +0100 Subject: [PATCH] refactor(RSADecryptor): Lazy Loading in Encryptor Getter integriert, um die Leistung zu verbessern. --- DigitalData.Core.Security/RSADecryptor.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/DigitalData.Core.Security/RSADecryptor.cs b/DigitalData.Core.Security/RSADecryptor.cs index 04be07a..83813c1 100644 --- a/DigitalData.Core.Security/RSADecryptor.cs +++ b/DigitalData.Core.Security/RSADecryptor.cs @@ -10,20 +10,19 @@ namespace DigitalData.Core.Security public bool IsEncrypted => Password is not null; - public IRSAEncryptor Encryptor + private readonly Lazy _lazyEncryptor; + + public IRSAEncryptor Encryptor => _lazyEncryptor.Value; + + internal RSADecryptor() { - get + _lazyEncryptor = new(() => new RSAEncryptor() { - return new RSAEncryptor() - { - Pem = _rsa.ExportRSAPublicKeyPem(), - Padding = Padding - }; - } + Pem = _rsa.ExportRSAPublicKeyPem(), + Padding = Padding + }); } - internal RSADecryptor() { } - [OnDeserialized] private void OnDeserialized(StreamingContext context) => Init();