From ca6745e0d4a4ad0361760c4d3588441003187d13 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Mon, 2 Aug 2021 10:01:21 -0400 Subject: [PATCH] Create key file if not exist --- PrivateData.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/PrivateData.cs b/PrivateData.cs index e22a245..6979d4a 100644 --- a/PrivateData.cs +++ b/PrivateData.cs @@ -6,12 +6,18 @@ using System; class PrivateData { private RSACryptoServiceProvider RSA; - + private string keyFile = "KeyInfo.xml"; public PrivateData() { - RSA = new RSACryptoServiceProvider(); - RSA.FromXmlString(File.ReadAllText("KeyInfo.xml")); + if (File.Exists(keyFile)) { + RSA = new RSACryptoServiceProvider(); + RSA.FromXmlString(File.ReadAllText(keyFile)); + } else { + RSA = new RSACryptoServiceProvider(4096); + string KeyInfo = RSA.ToXmlString(true); + File.WriteAllText(keyFile, KeyInfo); + } } public string EncryptString(string input)