Hi All, Here is the step by step flow for your requirement. 1.First create a class named 'Encryption64' as below
Imports System Imports System.IO Imports System.Xml Imports System.Text Imports System.Security.Cryptography
Public Class Encryption64 Private key() As Byte = {} Private IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
Public Function Decrypt(ByVal stringToDecrypt As String, _ ByVal sEncryptionKey As String) As String Dim inputByteArray(stringToDecrypt.Length) As Byte Try key = System.Text.Encoding.UTF8.GetBytes(Left(sEncryptionKey, 8)) Dim des As New DESCryptoServiceProvider() inputByteArray = Convert.FromBase64String(stringToDecrypt) Dim ms As New MemoryStream() Dim cs As New CryptoStream(ms, des.CreateDecryptor(key, IV), _ CryptoStreamMode.Write) cs.Write(inputByteArray, 0, inputByteArray.Length) cs.FlushFinalBlock() Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8 Return encoding.GetString(ms.ToArray()) Catch e As Exception Return e.Message End Try End Function
Public Function Encrypt(ByVal stringToEncrypt As String, _ ByVal SEncryptionKey As String) As String Try key = System.Text.Encoding.UTF8.GetBytes(Left(SEncryptionKey, 8)) Dim des As New DESCryptoServiceProvider() Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes( _ stringToEncrypt) Dim ms As New MemoryStream() Dim cs As New CryptoStream(ms, des.CreateEncryptor(key, IV), _ CryptoStreamMode.Write) cs.Write(inputByteArray, 0, inputByteArray.Length) cs.FlushFinalBlock() Return Convert.ToBase64String(ms.ToArray()) Catch e As Exception Return e.Message End Try End Function
End Class
2.Then use the function in your page as below - From here you are going to post the query
Public Function encryptQueryString(ByVal strQueryString As String) As String Dim oES As New Encryption64() Return oES.Encrypt(strQueryString, "!#$a54?3") End Function
3.How to use the above code
"http://www.mysite.com/mypage.aspx?ID=" + encryptQueryString("HERE YOU PUT THE VALUE TO PASS")
4. So encryption part is over , now you need to decrypt the query string on the other page.For the you need to write this function on that page( where you wants the query string)
Public Function decryptQueryString(ByVal strQueryString As String) As String Dim oES As New Encryption64() Return oES.Decrypt(strQueryString, "!#$a54?3") End Function
5.How to use the above code
dim ID as string ID = decryptQueryString(Request.QueryString("ID").Replace(" ", "+"))
6.Thats all , you will get the value of ID.Hope you all enjoyed...
Regards, Vinod Chattergee.S
|
| Author: Vishnu 14 Feb 2009 | Member Level: Bronze Points : 1 |
This Code very useful for protect querystring in addressbar. but this code very lengthy. any simple method to hide url in addressbar
|
| Author: Sasikumar 14 Feb 2009 | Member Level: Gold Points : 0 |
Not Helpful
|