Products » dgEncrypt User Guide

Method:  Key::ReadKeyRegistry

ReadKeyRegistry(Hive, KeyName, ValueName)

The ReadKeyRegistry method reads a value from a given location in the registry, and assigns it to the Key object.
 
Hive
The Hive argument is an enumerated constant, which defines the following five hexidecimal values:

HKeyClassesRoot  =  0x80000000
HKeyCurrentUser  =  0x80000001
HKeyLocalMachine  =  0x80000002
HKeyUsers  =  0x80000003
HKeyCurrentConfig  =  0x80000005

As the name of the argument suggests, each of these values corresponds to a particular hive within the registry. On Win32 platforms, the registry is a hierarchically structured database which contains information pertinent to the configuration of both the operating system and the software installed on the machine. This database is conceptually organized as a tree, with each node under the root indicating a major division of the database. The hives represent these immediate children of the registry root node, and provide the base for the pathnames of any subkeys that lie under them.
 
KeyName
The KeyName argument is the name of the registry subkey that contains the cipher key value. This name takes the form of a pathname, with the sections of the name representing subkeys, rather than folders. Thus, the name "SOFTWARE\WebSite" indicates the "WebSite" subkey, which is a child of the "SOFTWARE" subkey, which is, in turn, the child of a hive node within the registry. Note that if the subkey specified by the KeyName argument does not exist, the method will throw an error.
 
ValueName
The ValueName argument indicates the name of the value that holds the desired cipher key data. Each key in the registry contains zero or more values, which actually hold the data relavent to the subkey that owns them. Thus, when the ReadKeyRegistry method is called, the Key object will attempt to open the subkey indicated by the KeyName argument, and read the data stored in the value whose name is given by the ValueName argument. Note that if this value does not exist, the method will throw an error.
 
Example:
<%
Function UpdateCardNumber(lngUserID, strCardNumber)
    If lngUserID < 1 Or strCardNumber = "" Then
        UpdateCardNumber = False
        Exit Function
    End If

    Dim strCipherText
    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
    strCipherText = objCipher.EncryptStringHex(strCardNumber)

    Dim strQuery
    Dim cnnConn

    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
        UpdateCardNumber = False'
        Exit Function
    End If

    strQuery = "UPDATE CreditCards SET CardNumber = '" & strCipherText & "' WHERE UserID = " & lngUserID

    cnnConn.Execute strQuery

    cnnConn.Close

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

    UpdateCardNumber = True
End Function
%>