From 4e0e9073130b5aa94ff5c8d4f77701ae956d38db Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Sat, 7 Dec 2024 03:24:29 +0100 Subject: [PATCH] feat(RSAEncryptor): FileNotFoundEvent-Methode aktualisiert, um Datei zu erstellen, wenn nicht gefunden --- .../Cryptographer/RSACryptographer.cs | 2 +- .../Cryptographer/RSAEncryptor.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/DigitalData.Core.Security/Cryptographer/RSACryptographer.cs b/DigitalData.Core.Security/Cryptographer/RSACryptographer.cs index b86a42e..a38fd1e 100644 --- a/DigitalData.Core.Security/Cryptographer/RSACryptographer.cs +++ b/DigitalData.Core.Security/Cryptographer/RSACryptographer.cs @@ -5,7 +5,7 @@ namespace DigitalData.Core.Security.Cryptographer { public class RSACryptographer : IRSACryptographer { - private string? _pem; + protected string? _pem; public string Pem { diff --git a/DigitalData.Core.Security/Cryptographer/RSAEncryptor.cs b/DigitalData.Core.Security/Cryptographer/RSAEncryptor.cs index f25f64e..be21823 100644 --- a/DigitalData.Core.Security/Cryptographer/RSAEncryptor.cs +++ b/DigitalData.Core.Security/Cryptographer/RSAEncryptor.cs @@ -1,4 +1,5 @@ using DigitalData.Core.Abstractions.Security; +using DigitalData.Core.Security.Config; using DigitalData.Core.Security.Extensions; namespace DigitalData.Core.Security.Cryptographer @@ -16,5 +17,21 @@ namespace DigitalData.Core.Security.Cryptographer base.Init(); RSA.ImportFromPem(base.Pem); } + + public override void FileNotFoundEvent() + { + var new_decryptor = new RSADecryptor() + { + Pem = RSAFactory.Static.CreateRSAPrivateKeyPem() + }; + + _pem = new_decryptor.Encryptor.Pem; + + if (PemPath is not null) + Task.Run(async () => + { + await File.WriteAllTextAsync(_pem, PemPath); + }); + } } } \ No newline at end of file