Guys I need your help on this.
I have this one problem and I admitted I am a novice at this. This is a Code
Behind in an aspx page. You will see where I have the plus signs below in
SecureQueryStri ng2.vb where I am calling another Class called
"InvalidQuerySt ringException". My problem is where do I put this code so it
can be called from SecureQueryStri ng2.vb. I have tried to put it in the same
code behind SecureQueryStri ng2.vb and I get errors. How should I do this to
make it work and also check my .ASPX page to make sure I and referencing it
correctlly. Thanks for your help in advance.
Here is the code for InvalidQueryStr ingException:
=============== ===============
Public Class InvalidQueryStr ingException
Inherits System.Exceptio n
End Class
=============== ===============
Code Behind named: SecureQueryStri ng2.vb
=============== ===============
Imports System
Imports System.Collecti ons.Specialized
Imports System.Security .Cryptography
Imports System.Text
Imports System.Web
Namespace dma
Public Class SecureQueryStri ng
Inherits NameValueCollec tion
Private Const cryptoKey As String = "test"
Private ReadOnly IV As Byte() = New Byte(7) {240, 3, 45, 29, 0, 76,
173, 59}
Sub New()
End Sub
Sub New(ByVal encStr As String)
deserialize(Dec rypt(encStr))
End Sub
Public ReadOnly Property EncryptedString () As String
Get
Return HttpUtility.Url Encode(Encrypt( Serialize()))
End Get
End Property
Public Overrides Function ToString() As String
Return EncryptedString
End Function
Private Function Encrypt(ByVal serQS As String) As String
Dim buffer As Byte() = Encoding.ASCII. GetBytes(serQS)
Dim des As TripleDESCrypto ServiceProvider = New
TripleDESCrypto ServiceProvider
Dim md5 As MD5CryptoServic eProvider = New
MD5CryptoServic eProvider
des.Key =
md5.ComputeHash (ASCIIEncoding. ASCII.GetBytes( cryptoKey))
des.IV = IV
Return
Convert.ToBase6 4String(des.Cre ateEncryptor.Tr ansformFinalBlo ck(buffer, 0,
buffer.Length))
End Function
Private Function Decrypt(ByVal encQS As String) As String
Try
Dim buffer As Byte() = Convert.FromBas e64String(encQS )
Dim des As TripleDESCrypto ServiceProvider = New
TripleDESCrypto ServiceProvider
Dim MD5 As MD5CryptoServic eProvider = New
MD5CryptoServic eProvider
des.Key =
MD5.ComputeHash (ASCIIEncoding. ASCII.GetBytes( cryptoKey))
des.IV = IV
Return
Encoding.ASCII. GetString(des.C reateDecryptor( ).TransformFina lBlock(buffer,
0, buffer.Length() ))
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++++++++++++
Catch ex As CryptographicEx ception
Throw New InvalidQueryStr ingException
Catch ex As FormatException
Throw New InvalidQueryStr ingException
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++++++++++++
End Try
End Function
Private Sub Deserialize(ByV al decQS As String)
Dim nameValuePairs As String() = decQS.Split("&" )
Dim i As Integer
For i = 0 To nameValuePairs. Length - 1
Dim nameValue As String() = nameValuePairs( i).Split("=")
If nameValue.Lengt h = 2 Then
Me.Add(nameValu e(0), nameValue(1))
End If
Next
End Sub
Private Function Serialize() As String
Dim sb As StringBuilder = New StringBuilder
Dim key As String
For Each key In Me.AllKeys
sb.Append(key)
sb.Append("=")
sb.Append(Me(ke y))
sb.Append("&")
Next key
Return sb.ToString
End Function
End Class
End Namespace
Here is my .ASPX page code:
=============== =====
<%@ Page language="VB" src="SecureQuer yString2.vb" AutoEventWireup ="false"
Inherits="Secur eQueryString" %>
<%@ Import Namespace="dma" %>
<script language="VB" runat="server">
'Sending page
Dim qs
qs = new SecureQueryStri ng()
qs("Name") = "Test"
qs("Phone") = "704-822-8999"
Response.Redire ct("Data2.aspx? x=" + qs.ToString())
</script >
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitl ed Document</title>
</head>
<body>
</body>
</html>
--
Thanks,