Encryption Class

 This encryption class (VB | C#) contains methods to peform one-way MD5 hashing, and de/encrytion using a symmetric key. In order to use this class you must have have a symmetricHashKey key in your web.config.
<appSettings>
<add key="symmetricHashKey" value="some_value" />
</appSettings>

To use class for MD5 hashing, for example, first create an instance then put all the strings into an arraylist, then call the MD5Encryption method:

' VB<br />
Dim encryption As New Encryption<br />
Dim paramsArray as new ArrayList<br />
paramsArray.Add(a_value)<br />
paramsArray.Add(system.Configuration.ConfigurationMananger.AppSettings("symmetricHashKey").ToString)<br />
Dim hashedString As String = encryption.MD5Encryption(paramsArray)

Here’s an example of using this class to check a query string with that of your hashed string

' VB<br />
' Example querystring ?a=Value1&amp;b=Value2&amp;hash=some_hashed_string<br />
Function ValidateRequest()<br />
Dim c as New Encryption<br />
Dim paramsArray as New ArrayList<br />
paramsArray.Add(Request.QueryString("a"))<br />
paramsArray.Add(Request.Querystring("b"))<br />
paramsArray.Add(System.Configuration.ConfigurationMananger.AppSettings("symmetricHashKey").ToString)<br />
Dim hashedString As String = c.MD5Encyption(paramsArray)<br />
If hashedString = Request.QueryString("hash") Then<br />
return True<br />
Else<br />
return false<br />
End If<br />
End Function