Hi
I want to encrypt the query string appearing in the URL of a web page,
how to do this
for eg..
I have a Hyperlink column in GridView ,, when I click that column, I pass two parameters ,
these parameters should not be displayed in the URL ,,
It should be in encrypted form with some other numbers …
Any idea how to perform this
gridviewquerystringHyperLinkEncrypt
Best Regards
Winnie Cherian
-------------------------------------------
If you need to keep the data secure, a query string perhaps isn't the safest method to use - there are other ways of passing data between pages.
However, if you need to do it that way, here's an example of how to encrypt and decrypt a string that I got from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityCryptography.asp
I've pulled out a few bits which weren't relevant, see the URL above for the full example
using System; using System.IO; using System.Text; using System.Security.Cryptography;
namespace RC2CryptoServiceProvider_Examples { class MyMainClass { publicstatic void Main() { string original = "This is a much longer string of data than a public/private key algorithm will accept."; string roundtrip; ASCIIEncoding textConverter = new ASCIIEncoding(); RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider(); byte[] fromEncrypt; byte[] encrypted; byte[] toEncrypt; byte[] key; byte[] IV;
//Create a new key and initialization vector. rc2CSP.GenerateKey(); // You'll probably want to do this once, save it and use it in the sending and receiving pages rc2CSP.GenerateIV();
//Get the key and IV. key = rc2CSP.Key; IV = rc2CSP.IV;
//Get an encryptor. ICryptoTransform encryptor = rc2CSP.CreateEncryptor(key, IV);
//Encrypt the data. MemoryStream msEncrypt = new MemoryStream(); CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);
//Convert the data to a byte array. toEncrypt = textConverter.GetBytes(original);
//Write all data to the crypto stream and flush it. csEncrypt.Write(toEncrypt, 0, toEncrypt.Length); csEncrypt.FlushFinalBlock();
//Get encrypted array of bytes. encrypted = msEncrypt.ToArray(); // You can convert this to a string, HttpUtility.UrlEncode it and use it in your querystring - you'll have to do the reverse to decrypt
// You'll need code like this in your receving page to decrypt - you'll have to store the key somewhere in order to pass it // between the two pages //Get a decryptor that uses the same key and IV as the encryptor. ICryptoTransform decryptor = rc2CSP.CreateDecryptor(key, IV);
//Now decrypt the previously encrypted message using the decryptor // obtained in the above step. MemoryStream msDecrypt = new MemoryStream(encrypted); CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);
fromEncrypt = newbyte[encrypted.Length];
//Read the data out of the crypto stream. csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
//Convert the byte array back into a string. roundtrip = textConverter.GetString(fromEncrypt); } } }
-- Please Mark Posts that helped you as Answers, and share a summary of what solved the problem.
winniecheria...
Member
38 Points
38 Posts
Encrypt QueryString parameters in a GridView Hyperlink column
Aug 09, 2007 10:32 AM|LINK
I want to encrypt the query string appearing in the URL of a web page,
how to do this
for eg..
I have a Hyperlink column in GridView ,, when I click that column, I pass two parameters ,
these parameters should not be displayed in the URL ,,
It should be in encrypted form with some other numbers …
Any idea how to perform this
gridview querystring HyperLink Encrypt
Winnie Cherian
-------------------------------------------
klaus_b
Contributor
2847 Points
566 Posts
Re: Encrypt QueryString parameters in a GridView Hyperlink column
Aug 09, 2007 10:55 AM|LINK
Hi winniecherian,
may have a look at this article. The source is available and easy understandable. Only .NET classes are used. Try it.
Klaus
I haven't the faintest idea, but great many therefrom.
klaus_b@.NET
griff_1000
Participant
1330 Points
238 Posts
Re: Encrypt QueryString parameters in a GridView Hyperlink column
Aug 09, 2007 11:07 AM|LINK
If you need to keep the data secure, a query string perhaps isn't the safest method to use - there are other ways of passing data between pages.
However, if you need to do it that way, here's an example of how to encrypt and decrypt a string that I got from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityCryptography.asp
I've pulled out a few bits which weren't relevant, see the URL above for the full example