using System.Security.Cryptography;
public class CryptographyRSA()
{
private string PrivateKey = "<RSAKeyValue>YOUR_RSA_KEY</RSAKeyValue>";
private string PublicKey = "<RSAKeyValue>YOUR_RSA_KEY</RSAKeyValue>";
public CryptographyRSA(){}
public string EncryptText(string strToEncript)
{
byte[] bytes = new UnicodeEncoding().GetBytes(strToEncript));
RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
provider.FromXmlString(PublicKey);
byte[] inArray = provider.Encrypt(bytes, false);
provider = null;
return Convert.ToBase64String(inArray);
}
public string DecryptText(string strToDecript)
{
UnicodeEncoding encoding = new UnicodeEncoding();
RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
RSACryptoServiceProvider.UseMachineKeyStore = false;
provider.FromXmlString(PrivateKey);
byte[] rgb = Convert.FromBase64String(strToDecript);
byte[] bytes = provider.Decrypt(rgb, false);
provider = null;
return encoding.GetString(bytes);
}
}
Refactorings
No refactoring yet !
Rik Hemsley
August 30, 2008, August 30, 2008 18:40, permalink
So what are you hoping for help with? Compiling? Spell checking?
This is a simple example of Cryptography Class using RSA algorithm and Base64.
I did this in my notepad and I have not compiled to test the sintax. :)