Products » dgEncrypt User Guide

Method:  Cipher::DecryptStringHex

DecryptStringHex(CipherText)

The DecryptStringHex method decrypts a string of hexidecimal-encoded cipher text produced by a call to EncryptStringHex, and returns the resulting plain text as a string value.
 
CipherText
The CipherText argument is the string to be decrypted.
 
Example:
<%
Dim strUserName
Dim strPassWord

strUserName = Request.Form("UserName")

If strUserName = "" Then
    Response.Redirect "error.asp"
End If

strPassWord = Request.Form("PassWord")

If strPassWord = "" Then
    Response.Redirect "error.asp"
End If

Dim strCipherText
Dim cnnConn
Dim rsRecord

Set cnnConn = Server.CreateObject("ADODB.Connection")
cnnConn.Open "Driver={SQL Server};" & _
        "Server=bigmoe;" & _
        "Database=random_stuff;" & _
        "Uid=sa;" & _
        "Pwd=!goombah!;"

' adStateOpen = 1
If cnnConn.State <> 1 Then
    Response.Redirect "error.asp"
End If

Set rsRecord = cnnConn.Execute("SELECT PassWord FROM Users WHERE UserName = '" & strUserName & "'")

If rsRecord.EOF Then
    cnnConn.Close
    Response.Redirect "error.asp"
End If

strCipherText = rsRecord("PassWord")

rsRecord.Close
cnnConn.Close

Dim blnValid
Dim strFileName
Dim strCompare
Dim objKey
Dim objCipher

strFileName = Server.MapPath("../Include/Keys/LoginKey.dat")

Set objKey = Server.CreateObject("dgEncrypt.Key")
objKey.ReadKeyFile strFileName

Set objCipher = Server.CreateObject("dgEncrypt.Cipher")
objCipher.SetKey objKey
strCompare = objCipher.DecryptStringHex(strCipherText)

If strPassWord = strCompare Then
    blnValid = True
End If

Set rsRecord = Nothing
Set cnnConn = Nothing
Set objCipher = Nothing
Set objKey = Nothing

If blnValid Then
    Response.Redirect "login_success.asp"
Else
    Response.Redirect "login_fail.asp"
End If
%>