1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
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. :)