Products » dgEncrypt User Guide

Method:  Cipher::DecryptStringBinary

DecryptStringBinary(CipherText)

The DecryptStringBinary method decrypts the raw binary cipher text produced by a call to EncryptStringBinary, and returns the resulting plain text as a string value.
 
CipherText
The CipherText argument is the raw binary value to be decrypted.
 
Example:
<%
Dim lngCustomerID
Dim lngCardType

If Request.Form("CustomerID") = "" Then
    Response.Redirect "error.asp"
End If

lngCustomerID = CLng(Request.Form("CustomerID"))

If Request.Form("CardType") = "" Then
    Response.Redirect "error.asp"
End If

lngCardType = CLng(Request.Form("CardType"))

Dim CipherText
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 CardNumber FROM CustomerCards WHERE CutomerID = " & lngCustomerID & " AND CardType = " & strCardType)

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

CipherText = rsRecord("CardNumber")

rsRecord.Close
cnnConn.Close

Dim strCardNumber
Dim objKey
Dim objCipher

' HKeyLocalMachine = &H80000002
Set objKey = Server.CreateObject("dgEncrypt.Key")
objKey.ReadKeyRegistry &H80000002, "SOFTWARE\Website", "CCKey"

Set objCipher = Server.CreateObject("dgEncrypt.Cipher")
objCipher.SetKey objKey
strCardNumber = objCipher.DecryptStringBinary(CipherText)


' . . .


Set rsRecord = Nothing
Set cnnConn = Nothing
Set objCipher = Nothing
Set objKey = Nothing
%>