update rsa implementation
authorStricted <info@stricted.net>
Thu, 10 Nov 2016 19:15:31 +0000 (20:15 +0100)
committerStricted <info@stricted.net>
Thu, 10 Nov 2016 19:15:31 +0000 (20:15 +0100)
SpeedportHybridControl.Implementations/Cryptography.cs

index 478ecd01f68e82cdc15fc0acd19792ac9d1a36af..fa94490946b85175159824fdc91c169963bf6be1 100644 (file)
@@ -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));