Products » dgEncrypt User Guide

Method:  Key::ReadKeyFile

ReadKeyFile(FileName)

The ReadKeyFile method retrieves the cipher key value from a file produced by a call to the WriteKeyFile method, and assigns it to the Key object.
 
FileName
The FileName is the full pathname of the file from which the cipher key value will be read. If the specified file does not exist, the method will throw an error.
 
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
%>