C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Encryption »

Encryption and Decryption of a Querystring


Posted Date: 05 Aug 2009    Resource Type: Code Snippets    Category: Encryption
Author: Shunmuganathan MMember Level: Diamond    
Rating: 1 out of 5Points: 9



Encryption and Decryption of a Querystring.



We can send the querystring by Encryption mode and receiver it in Decryption mode.

Following is the sample code for encrypt


public static string KEY = "K6u8#m2a";
public static string EncryptQueryString(string stringToEncrypt)
{
byte[] key = { };
byte[] IV = { 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78 };
try
{
key = Encoding.UTF8.GetBytes(KEY);
using (DESCryptoServiceProvider oDESCrypto = new DESCryptoServiceProvider())
{
byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
MemoryStream MyMemoryStream = new MemoryStream();
CryptoStream MyCryptoStream = new CryptoStream(MyMemoryStream,
MyDESCrypto.CreateEncryptor(key, IV), CryptoStreamMode.Write);
MyCryptoStream.Write(inputByteArray, 0, inputByteArray.Length);
MyCryptoStream.FlushFinalBlock();
return Convert.ToBase64String(MyMemoryStream.ToArray());
}
}
catch (Exception ex)
{

throw ex;
}
}



Following is the code for Decrypt of Querystring



public static string DecryptQueryString(string stringToDecrypt)
{
byte[] key = { };
byte[] IV = { 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78 };
stringToDecrypt = stringToDecrypt.Replace(" ", "+");
byte[] inputByteArray = new byte[stringToDecrypt.Length];


try
{
key = Encoding.UTF8.GetBytes(KEY);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(stringToDecrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
Encoding encoding = Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (Exception ex)
{

throw ex;
}
}




By
Nathan



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Encryption and Decryption of a Querystring  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Encryption and Decryption of Password using VB.NET
Previous Resource: Password Encryption & Decryption using C#
Return to Discussion Resource Index
Post New Resource
Category: Encryption


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use