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