From: Stricted Date: Thu, 10 Nov 2016 19:15:31 +0000 (+0100) Subject: update rsa implementation X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=69507dd0936663095fa4de1eff27c6f2ceb8bfcb;p=GitHub%2FStricted%2FSpeedportHybridControl.git update rsa implementation --- diff --git a/SpeedportHybridControl.Implementations/Cryptography.cs b/SpeedportHybridControl.Implementations/Cryptography.cs index 478ecd0..fa94490 100644 --- a/SpeedportHybridControl.Implementations/Cryptography.cs +++ b/SpeedportHybridControl.Implementations/Cryptography.cs @@ -11,13 +11,16 @@ namespace SpeedportHybridControl.Implementations // store key in keycontainer, this generates a new key if none exist CspParameters cp = new CspParameters(); cp.KeyContainerName = "SpeedportHybridControl"; - RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp); - return rsa.ToXmlString(true); + RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048, cp); + string result = rsa.ToXmlString(true); + rsa.Dispose(); + + return result; } public static string Encrypt(string clearText) { - RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048); + RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); byte[] clearBytes = Encoding.Unicode.GetBytes(clearText); rsa.FromXmlString(GetKeyFromContainer()); string result = Convert.ToBase64String(rsa.Encrypt(clearBytes, true)); @@ -28,7 +31,7 @@ namespace SpeedportHybridControl.Implementations public static string Decrypt(string cipherText) { - RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048); + RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); byte[] cipherBytes = Convert.FromBase64String(cipherText); rsa.FromXmlString(GetKeyFromContainer()); string result = Encoding.Unicode.GetString(rsa.Decrypt(cipherBytes, true));