HI,
Its so easy.
Please refer below code for this.
Pass value in string which you want to encrypt or decrypt.
using System.Text;
using System.Security.Cryptography;
using System.IO;
public static string EncryptQueryString(string str)
{
byte[] bytes = ASCIIEncoding.ASCII.GetBytes("proposal");
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);
StreamWriter writer = new StreamWriter(cryptoStream);
writer.Write(str);
writer.Flush();
cryptoStream.FlushFinalBlock();
writer.Flush();
return HttpUtility.UrlEncode(Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length));
}
public static string DecryptQueryString(string cryptedstr)
{
cryptedstr = cryptedstr.Replace(" ", "+");
byte[] bytes = ASCIIEncoding.ASCII.GetBytes("proposal");
if (String.IsNullOrEmpty(cryptedstr))
{
throw new ArgumentNullException("String can not be null.");
}
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(cryptedstr));
CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateDecryptor(bytes, bytes), CryptoStreamMode.Read);
StreamReader reader = new StreamReader(cryptoStream);
return HttpUtility.UrlDecode(reader.ReadToEnd());
}