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 » ASP.NET WebForms »

Encryption/Decryption of Address Bar


Posted Date: 14 Feb 2009    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: Vinod ChattergeeMember Level: Silver    
Rating: 1 out of 5Points: 10



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



Responses

Author: Vishnu    14 Feb 2009Member 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 2009Member Level: Gold   Points : 0
Not Helpful


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Encryption  .  Decryption  .  Address Bar  .  

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: Create header dynamically in gridview using ASP.NET
Previous Resource: Download music file in ASP.NET
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use