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,19 +10,18 @@ namespace DigitalData.Core.Security public bool IsEncrypted => Password is not null; - public IRSAEncryptor Encryptor - { - get - { - return new RSAEncryptor() - { - Pem = _rsa.ExportRSAPublicKeyPem(), - Padding = Padding - }; - } - } + private readonly Lazy _lazyEncryptor; - internal RSADecryptor() { } + public IRSAEncryptor Encryptor => _lazyEncryptor.Value; + + internal RSADecryptor() + { + _lazyEncryptor = new(() => new RSAEncryptor() + { + Pem = _rsa.ExportRSAPublicKeyPem(), + Padding = Padding + }); + } [OnDeserialized] private void OnDeserialized(StreamingContext context) => Init();