Post by bip on Jul 3, 2008 6:08:23 GMT -5
I am trying to use VBCorLib with a classic ASP application in which I am trying to encrypt a user id and pass it to a URL string. Not much of a programmer, but am trying to adapt the VB example to pass this information to the URL. Any ideas where I could find an example? Below is the VB code. I would appreciate any help anyone might be able to give.
Private Sub Main()
dim custID
' Create a new DES key.
Dim Key As New DESCryptoServiceProvider
' Setting key
Set Key = "KeyHere"
' Pulling Customer ID from cookie to encrypt and pass to url
custID = request.cookies("customerID")
' Encrypt a string to a byte array.
Dim Buffer() As Byte
Buffer = Encrypt(custID, Key)
' Decrypt the byte array back to a string.
Dim PlainText As String
PlainText = Decrypt(Buffer, Key)
' Display the PlainText value to the console.
Console.WriteLine PlainText
Console.ReadKey
End Sub Main
' Encrypt the string.
Private Function Encrypt(ByVal PlainText As String, ByVal Key As SymmetricAlgorithm) As Byte()
Dim Buffer() As Byte
Buffer = StrConv(PlainText, vbFromUnicode)
Dim Encryptor As ICryptoTransform
Set Encryptor = Key.CreateEncryptor
Encrypt = Encryptor.TransformFinalBlock(Buffer, 0, cArray.GetLength(Buffer))
End Function
' Decrypt the byte array.
Public Function Decrypt(ByRef CypherText() As Byte, ByVal Key As SymmetricAlgorithm) As String
Dim Decryptor As ICryptoTransform
Set Decryptor = Key.CreateDecryptor
Dim Buffer() As Byte
Buffer = Decryptor.TransformFinalBlock(CypherText, 0, cArray.GetLength(CypherText))
Decrypt = StrConv(Buffer, vbUnicode)
End Function
Private Sub Main()
dim custID
' Create a new DES key.
Dim Key As New DESCryptoServiceProvider
' Setting key
Set Key = "KeyHere"
' Pulling Customer ID from cookie to encrypt and pass to url
custID = request.cookies("customerID")
' Encrypt a string to a byte array.
Dim Buffer() As Byte
Buffer = Encrypt(custID, Key)
' Decrypt the byte array back to a string.
Dim PlainText As String
PlainText = Decrypt(Buffer, Key)
' Display the PlainText value to the console.
Console.WriteLine PlainText
Console.ReadKey
End Sub Main
' Encrypt the string.
Private Function Encrypt(ByVal PlainText As String, ByVal Key As SymmetricAlgorithm) As Byte()
Dim Buffer() As Byte
Buffer = StrConv(PlainText, vbFromUnicode)
Dim Encryptor As ICryptoTransform
Set Encryptor = Key.CreateEncryptor
Encrypt = Encryptor.TransformFinalBlock(Buffer, 0, cArray.GetLength(Buffer))
End Function
' Decrypt the byte array.
Public Function Decrypt(ByRef CypherText() As Byte, ByVal Key As SymmetricAlgorithm) As String
Dim Decryptor As ICryptoTransform
Set Decryptor = Key.CreateDecryptor
Dim Buffer() As Byte
Buffer = Decryptor.TransformFinalBlock(CypherText, 0, cArray.GetLength(CypherText))
Decrypt = StrConv(Buffer, vbUnicode)
End Function