// 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));
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));