Crypt Class
Crypt Class
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
Module:
clsCryptoAPI.cls
Description:
Thanks to:
SIMPLEBLOB
PUBLICKEYBLOB
PRIVATEKEYBLOB
PLAINTEXTKEYBLOB
As
As
As
As
Long
Long
Long
Long
As
As
As
As
As
=
=
=
=
1
6
7
8
Long
Long
Long
Long
Long
As Long = 0
As Long = 1536
As Long = 2048
=
=
=
=
=
0
8192
16384
24576
32768
Private
Private
Private
Private
Const
Const
Const
Const
ALG_SID_DES
ALG_SID_RC2
ALG_SID_3DES
ALG_SID_3DES_112
As
As
As
As
Long
Long
Long
Long
=
=
=
=
1
2
3
9
As Long = 1
As
As
As
As
As
As
ALG_SID_MD2
ALG_SID_MD4
ALG_SID_MD5
ALG_SID_SHA
ALG_SID_SHA1
HP_HASHVAL
Long
Long
Long
Long
Long
Long
=
=
=
=
=
=
1
2
3
4
4
2
As Long = 1
As Long = 101
As Long = 102
As Long = 103
' a function's return value indicates that such a call will return
' useful data. That is because some functions call SetLastError(0) when
' they succeed, wiping out the error code set by the most recently
' failed function.
Private Declare Function GetLastError Lib "kernel32" () As Long
' The CryptHashData function adds data to a specified hash object.
' This function and CryptHashSessionKey can be called multiple
' times to compute the hash of long or discontinuous data streams.
Private Declare Function CryptHashData Lib "advapi32.dll" _
(ByVal hhash As Long, ByVal pbData As String, _
ByVal dwDataLen As Long, ByVal dwFlags As Long) As Long
' Alias of CryptHashData
Private Declare Function CryptHashDataString Lib "advapi32.dll" _
Alias "CryptHashData" (ByVal hhash As Long, _
ByVal bData As String, ByVal dwDataLen As Long, _
ByVal dwFlags As Long) As Long
' Alias of CryptHashData
Private Declare Function CryptHashDataBytes Lib "advapi32.dll" _
Alias "CryptHashData" (ByVal hhash As Long, _
bData As Byte, ByVal dwDataLen As Long, _
ByVal dwFlags As Long) As Long
' The CryptCreateHash function initiates the hashing of a stream of
' data. It creates and returns to the calling application a handle
' to a CSP hash object. This handle is used in subsequent calls to
' CryptHashData and CryptHashSessionKey to hash session keys and
' other streams of data.
Private Declare Function CryptCreateHash Lib "advapi32.dll" _
(ByVal hProv As Long, ByVal algid As Long, _
ByVal hkey As Long, ByVal dwFlags As Long, _
ByRef phHash As Long) As Long
' The CryptSignHash function signs data. Because all signature
' algorithms are asymmetric and thus slow, the CryptoAPI does not
' allow data be signed directly. Instead, data is first hashed and
' CryptSignHash is used to sign the hash.
Private Declare Function CryptSignHash Lib "advapi32.dll" _
Alias "CryptSignHashA" (ByVal hhash As Long, _
ByVal hkey As Long, ByVal Description As Long, _
ByVal dwFlags As Long, ByVal pData As Long, _
dwDataLength As Long) As Long
' The CryptVerifySignature function verifies the signature of a
' hash object. Before calling this function, CryptCreateHash must be
' called to create the handle of a hash object. CryptHashData or
' CryptHashSessionKey is then used to add data or session keys to the
' hash object.
Private Declare Function CryptVerifySignature Lib "advapi32.dll" _
Alias "CryptVerifySignatureA" (ByVal hhash As Long, _
ByVal pData As Long, ByVal datalength As Long, _
ByVal PublicKey As Long, ByVal Description As Long, _
ByVal dwFlags As Long) As Long
' The CryptGetHashParam function retrieves data that governs the
' operations of a hash object. The actual hash value can be
' retrieved by using this function.
Private Declare Function CryptGetHashParam Lib "advapi32.dll" _
Lib "advapi32.dll" _
As Long, _
_
Long) As Long
' in phKey. This handle can then be used as needed with any CryptoAPI
' function requiring a key handle. The calling application must specify
' the algorithm when calling this function. Because this algorithm type is
' kept bundled with the key, the application does not need to specify the
' algorithm later when the actual cryptographic operations are performed.
Private Declare Function CryptGenKey Lib "advapi32.dll" _
(ByVal hProv As Long, ByVal algid As Long, _
ByVal dwFlags As Long, phKey As Long) As Long
' The CryptDeriveKey function generates cryptographic session keys derived
' from a base data value. This function guarantees that when the same CSP
' and algorithms are used, the keys generated from the same base data are
' identical. The base data can be a password or any other user data. This
' function is the same as CryptGenKey, except that the generated session
' keys are derived from base data instead of being random. CryptDeriveKey
' can only be used to generate session keys. It cannot generate
' public/private key pairs.
Private Declare Function CryptDeriveKey Lib "advapi32.dll" _
(ByVal hProv As Long, ByVal algid As Long, _
ByVal hBaseData As Long, ByVal dwFlags As Long, _
ByRef phKey As Long) As Long
' The CryptDestroyKey function releases the handle referenced by the hKey
' parameter. After a key handle has been released, it becomes invalid and
' cannot be used again.
Private Declare Function CryptDestroyKey Lib "advapi32.dll" _
(ByVal hkey As Long) As Long
' The CryptGetKeyParam function retrieves data that governs the operations
' of a key. If the Microsoft Cryptographic Service Provider is used, the
' base symmetric keying material is not obtainable by this function or any
' other function.
Private Declare Function CryptGetKeyParam Lib "advapi32.dll" _
(ByVal hkey As Long, ByVal dwParam As Long, _
ByVal pbData As Long, pdwDataLen As Long, _
ByVal dwFlags As Long) As Long
' The CryptSetKeyParam function customizes various aspects of a session
' key's operations. The values set by this function are not persisted
' to memory and can only be used with in a single session.
Private Declare Function CryptSetKeyParam Lib "advapi32.dll" _
(ByVal hkey As Long, ByVal dwParam As Long, _
ByVal pbData As Long, ByVal dwFlags As Long) As Long
' The CryptExportKey function exports a cryptographic key or a key pair
' from a cryptographic service provider (CSP) in a secure manner.
Private Declare Function CryptExportKey Lib "advapi32.dll" _
(ByVal hkey As Long, ByVal hExpKey As Long, _
ByVal dwBlobType As Long, ByVal dwFlags As Long, _
ByVal pbData As Long, pdwDataLen As Long) As Long
' The CryptImportKey function transfers a cryptographic key from a key
' BLOB into a cryptographic service provider (CSP).This function can be
' used to import an Schannel session key, regular session key, public
' key, or public/private key pair. For all but the public key, the key
' or key pair is encrypted.
Private Declare Function CryptImportKey Lib "advapi32.dll" _
(ByVal hProv As Long, ByVal pbData As Long, _
ByVal dwDataLength As Long, ByVal hPubKey As Long, _
ByVal dwFlags As Long, pKeyval As Long) As Long
' The CryptEncrypt function encrypts data. The algorithm used to encrypt
' the data is designated by the key held by the CSP module and is
' referenced by the hKey parameter.
Private Declare Function CryptEncrypt Lib "advapi32.dll" _
(ByVal hkey As Long, ByVal hhash As Long, ByVal Final As Long, _
ByVal dwFlags As Long, ByVal pbData As String, _
ByRef pdwDataLen As Long, ByVal dwBufLen As Long) As Long
' The CryptDecrypt function decrypts data previously encrypted using
' CryptEncrypt function.
Private Declare Function CryptDecrypt Lib "advapi32.dll" _
(ByVal hkey As Long, ByVal hhash As Long, _
ByVal Final As Long, ByVal dwFlags As Long, _
ByVal pbData As String, ByRef pdwDataLen As Long) As Long
' The CryptGetProvParam function retrieves parameters that govern the
' operations of a cryptographic service provider (CSP).
Private Declare Function CryptGetProvParam Lib "advapi32.dll" _
(ByVal hProv As Long, ByVal dwParam As Long, _
pbData As Any, pdwDataLen As Long, _
ByVal dwFlags As Long) As Long
' Alias of CryptGetProvParam
Private Declare Function CryptGetProvParamString Lib "advapi32.dll" _
Alias "CryptGetProvParam" (ByVal hProv As Long, _
ByVal dwParam As Long, ByVal pbData As String, _
pdwDataLen As Long, ByVal dwFlags As Long) As Long
' ***************************************************************************
'
Property area
' ***************************************************************************
Public Property Let InputData(arInData() As Byte)
Attribute InputData.VB_Description = "Input only. Data to be Encrypted/Decrypte
d."
' --------------------------------------------------------------------------' Input data only in byte array
' --------------------------------------------------------------------------m_strInputData = ByteArrayToString(arInData())
End Property
Public Property Get OutputData() As Byte()
Attribute OutputData.VB_Description = "Read only. Return encrypted/decrypted da
ta in byte array format."
' --------------------------------------------------------------------------' Output data only in byte array
' --------------------------------------------------------------------------OutputData = m_abytOutputData
End Property
Public Property Get EnhancedProvider() As Boolean
Attribute EnhancedProvider.VB_Description = "Returns a boolean flag designating
if the enhanced provider is being used."
' ---------------------------------------------------------------------------
'
FALSE = Create random data password. Used for initialization
'
vectors.
' --------------------------------------------------------------------------' --------------------------------------------------------------------------' See if we are to use the default password or create one on the fly
' --------------------------------------------------------------------------m_blnUseDefaultPWD = blnUseDefaultPWD
End Property
' ***************************************************************************
'
Functions and Procedures
' ***************************************************************************
Public Function ByteArrayToString(arByte() As Byte) As String
Attribute ByteArrayToString.VB_Description = "Convert a byte array to string for
mat"
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
***************************************************************************
Routine:
ByteArrayToString
Description:
Parameters:
Returns:
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------03-OCT-2000 Kenneth Ives kenaso@home.com
Modified and documented
20-JAN-2001 VB2-The-Max http://www.vb2themax.com/
From an article titled "10 Hot Tips from VB-2-the-Max"
by Francesco Balena
This is tip no.9 on faster string concatenation with a little
modification.
24-JUL-2001 Kenneth Ives kenaso@home.com
Modified and added documentation
***************************************************************************
As Long = 10000
lngMax = UBound(arByte)
lngPaddingLen = (ADD_SPACES * 9)
strOutput = Space$(lngPaddingLen)
'
'
'
'
--------------------------------------------------------------------------Unload the byte array and convert each character back to its ASCII
character value
--------------------------------------------------------------------------For lngLoop = 0 To lngMax - 1
strTemp = Chr$(arByte(lngLoop)) ' Convert each byte to an ASCII character
lngLength = Len(strTemp)
' see if some more padding has to be added to the output string
If (lngIndexPointer + lngLength) >= lngPaddingLen Then
lngPaddingLen = lngPaddingLen + ADD_SPACES ' boost blank space counter
strOutput = strOutput & Space$(ADD_SPACES) ' append some blank spaces
End If
' insert data into output string
Mid$(strOutput, lngIndexPointer, lngLength) = strTemp
' increment output string pointer
lngIndexPointer = lngIndexPointer + lngLength
Next
' --------------------------------------------------------------------------' Return the string data
' --------------------------------------------------------------------------strOutput = RTrim$(strOutput) ' remove trailing blanks
ByteArrayToString = strOutput ' return data string
' --------------------------------------------------------------------------' Empty variables
' --------------------------------------------------------------------------strOutput = String$(250, 0)
End Function
Public Function ConvertByteToHex(ByRef abytData() As Byte) As String
Attribute ConvertByteToHex.VB_Description = "Convert byte array data to two char
acter hex format and return in a single string."
'
'
'
'
'
'
'
'
'
'
'
'
'
'
***************************************************************************
Routine:
ConvertByteFromHex
Description:
Parameters:
Returns:
data string
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- --------------------------------------------------------------
'
'
'
'
'
'
'
'
'
'
As Long = 10000
Next
strOutput = RTrim$(strOutput)
Else
strOutput = ""
End If
***************************************************************************
Routine:
ConvertStringFromHex
Description:
Parameters:
Returns:
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------15-DEC-2000 Kenneth Ives kenaso@home.com
Modified and documented
20-JAN-2001 VB2-The-Max http://www.vb2themax.com/
From an article titled "10 Hot Tips from VB-2-the-Max"
by Francesco Balena
This is tip no.9 on faster string concatenation with a little
modification.
24-JUL-2001 Kenneth Ives kenaso@home.com
Modified and added documentation
***************************************************************************
As Long = 10000
lngPaddingLen = (ADD_SPACES * 9)
strOutput = Space$(lngPaddingLen)
'
'
'
'
--------------------------------------------------------------------------See if the hex data string can be divided evenly by two. If not, then the
data is corrupted.
--------------------------------------------------------------------------If lngMax Mod 2 <> 0 Then
MsgBox "Data string is corrupted. Cannot be Decrypted.", _
vbCritical Or vbOKOnly, "Data corrupted"
Exit Function
End If
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
Returns:
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------15-DEC-2000 Kenneth Ives kenaso@home.com
Modified and documented
20-JAN-2001 VB2-The-Max http://www.vb2themax.com/
From an article titled "10 Hot Tips from VB-2-the-Max"
by Francesco Balena
This is tip no.9 on faster string concatenation with a little
modification.
24-JUL-2001 Kenneth Ives kenaso@home.com
Modified and added documentation
***************************************************************************
As Long = 10000
End If
' insert data into output string
Mid$(strOutput, lngIndexPointer, lngLength) = strTemp
' increment output string pointer
lngIndexPointer = lngIndexPointer + lngLength
Next
' --------------------------------------------------------------------------' remove trailing blanks
' --------------------------------------------------------------------------strOutput = RTrim$(strOutput) ' remove trailing blanks
' --------------------------------------------------------------------------' Return hex string
' --------------------------------------------------------------------------If blnRetUppercase Then
ConvertStringToHex = StrConv(strOutput, vbUpperCase)
Else
ConvertStringToHex = strOutput
End If
' --------------------------------------------------------------------------' Empty variables
' --------------------------------------------------------------------------strOutput = String$(250, 0)
End Function
Public Function CreateHash(Optional ByVal strInText As String = "", _
Optional ByVal intHashChoice As Integer = 1, _
Optional ByVal blnConvertToHex As Boolean = True, _
Optional ByVal blnAppendPassword As Boolean = False, _
Optional ByVal blnCaseSensitive As Boolean = False) As String
Attribute CreateHash.VB_Description = "Generate a one-way hash string from a str
ing of data. Hash types are: 1=MD5 2=MD4 3=MD2 4=SHA"
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
***************************************************************************
Routine:
CreateHash
Description:
Parameters:
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------01-DEC-2000 Kevin Matthew Goss
Wrote routine
15-DEC-2000 Kenneth Ives kenaso@home.com
Modified and documented
24-JUL-2001 Kenneth Ives kenaso@home.com
Modified parameters and building password
09-SEP-2001 Kenneth Ives kenaso@home.com
Documented and modified password creation
***************************************************************************
abytPWord = GetPassword(m_blnUseDefaultPWD)
strPassword = ByteArrayToString(abytPWord())
Erase abytPWord()
ReDim abytPWord(0)
ord
tring
ze
End If
strInText = strInText & strPassword
End If
'
'
'
'
'
'
'
'
'
'
' ---------------------------------------------------------------------------
***************************************************************************
Routine:
CreateRandom
Description:
Parameters:
Returns:
===========================================================================
'
'
'
'
'
'
'
'
'
'
'
'
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------01-DEC-2000 Kevin Matthew Goss
Routine created
03-OCT-2000 Kenneth Ives kenaso@home.com
Modified and documented
24-JUL-2001 Kenneth Ives kenaso@home.com
Reversed boolean parameters. Added additional seed values.
09-SEP-2001 Kenneth Ives kenaso@home.com
Documented and modified adding additional seeding.
***************************************************************************
'
'
'
'
--------------------------------------------------------------------------Now we have an additional seed for the random number generator. Be sure to
append additional space for the return data. Excess will be removed.
--------------------------------------------------------------------------strRndBuffer = strRndBuffer & Space$(lngDataLength)
***************************************************************************
Routine:
CreateSaltValue
Description:
Parameters:
Returns:
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------03-OCT-2000 Kenneth Ives kenaso@home.com
Modified and documented
24-JUL-2001 Kenneth Ives kenaso@home.com
Added boolean parameter
09-SEP-2001 Kenneth Ives kenaso@home.com
Documented and added 9 to bad ASCII values
' ***************************************************************************
' --------------------------------------------------------------------------' Define local variables
' --------------------------------------------------------------------------Dim intChar
As Integer
Dim lngIndex As Long
Dim strOutput As String
' --------------------------------------------------------------------------' Initialize variables
' --------------------------------------------------------------------------strOutput = ""
' --------------------------------------------------------------------------' Create salt value string using 0-9, A-Z, a-z only
' --------------------------------------------------------------------------If blnUseLettersNumbersOnly Then
For lngIndex = 1 To lngReturnLength
intChar = Int(Rnd2(48!, 122!))
Select Case intChar
Case 58 To 64, 91 To 96
intChar = intChar + 9
End Select
***************************************************************************
Routine:
Decrypt
Description:
Parameters:
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
Returns:
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------00-Feb-1998 Sam Patterson's COMponent builder Article in Visual Basic
Programmers Journal, "Secure Your Apps with CryptoAPI".
Great magazine to subscribe to.
29-DEC-2000 Kenneth Ives kenaso@home.com
Modified and documented
24-JUL-2001 Kenneth Ives kenaso@home.com
Added parameters to determine type of hash and cipher
algorithms to use
09-SEP-2001 Kenneth Ives kenaso@home.com
Changed to a function routine. Added parameters for hash and
cipher selections.
***************************************************************************
***************************************************************************
Routine:
CryptoDecrypt
Description:
Returns:
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------00-Feb-1998 Sam Patterson's COMponent builder Article in Visual Basic
Programmers Journal, "Secure Your Apps with CryptoAPI".
Great magazine to subscribe to.
29-DEC-2000 Kenneth Ives kenaso@home.com
Modified and documented
24-JUL-2001 Kenneth Ives kenaso@home.com
Modified and documented
09-SEP-2001 Kenneth Ives kenaso@home.com
Changed to a function routine. Added parameters for hash and
cipher selections. Corrected bad coding when calling
CryptDecrypt() function.
***************************************************************************
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
lngLength
lngCipherType
lngHExchgKey
lngCryptLength
lngCryptBufLen
strCryptBuffer
strOutputData
strPassword
As
As
As
As
As
As
As
As
Long
Long
Long
Long
Long
String
String
String
***************************************************************************
Routine:
Encrypt
Description:
Parameters:
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------00-Feb-1998 Sam Patterson's COMponent builder Article in Visual Basic
Programmers Journal, "Secure Your Apps with CryptoAPI".
Great magazine to subscribe to.
29-DEC-2000 Kenneth Ives kenaso@home.com
Modified and documented
24-JUL-2001 Kenneth Ives kenaso@home.com
Added parameters to determine type of hash and cipher
algorithms to use
09-SEP-2001 Kenneth Ives kenaso@home.com
Changed to a function routine. Added parameters for hash and
cipher selections.
***************************************************************************
***************************************************************************
Routine:
CryptoEncrypt
Description:
Returns:
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------00-Feb-1998 Sam Patterson's COMponent builder Article in Visual Basic
Programmers Journal, "Secure Your Apps with CryptoAPI".
Great magazine to subscribe to.
29-DEC-2000 Kenneth Ives kenaso@home.com
Modified and documented
24-JUL-2001 Kenneth Ives kenaso@home.com
Modified and documented
09-SEP-2001 Kenneth Ives kenaso@home.com
Changed to a function routine. Added parameters for hash and
cipher selections. Corrected bad coding when calling
CryptEncrypt() function.
***************************************************************************
' ---------------------------------------------------------------------------
strPassword = ByteArrayToString(m_abytPWord())
End If
End If
' --------------------------------------------------------------------------' Create a hash object
' --------------------------------------------------------------------------If Not CBool(CryptCreateHash(m_lngCryptContext, lngHashType, ByVal 0&, _
ByVal 0&, lngHashHwd)) Then
MsgBox "Error: " & CStr(GetLastError) & " during CryptCreateHash!", _
vbExclamation Or vbOKOnly, "Encryption Errors"
GoTo CleanUp
End If
' --------------------------------------------------------------------------' Hash in the password text
' --------------------------------------------------------------------------If Not CBool(CryptHashData(lngHashHwd, strPassword, Len(strPassword), ByVal 0&
)) Then
MsgBox "Error: " & CStr(GetLastError) & " during CryptHashData!", _
vbExclamation Or vbOKOnly, "Encryption Errors"
GoTo CleanUp
End If
' --------------------------------------------------------------------------' Create a session key from the hash object
' --------------------------------------------------------------------------If Not CBool(CryptDeriveKey(m_lngCryptContext, lngCipherType, _
lngHashHwd, ByVal 0&, lngHkey)) Then
MsgBox "Error: " & CStr(GetLastError) & " during CryptDeriveKey!", _
vbExclamation Or vbOKOnly, "Encryption Errors"
GoTo CleanUp
End If
' --------------------------------------------------------------------------' Destroy hash object
' --------------------------------------------------------------------------If lngHashHwd <> 0 Then
lngRetCode = CryptDestroyHash(lngHashHwd)
End If
lngHashHwd = 0
' --------------------------------------------------------------------------' Prepare data for encryption.
' --------------------------------------------------------------------------lngCryptLength = Len(m_strInputData)
lngCryptBufLen = lngCryptLength * 2
strCryptBuffer = String$(lngCryptBufLen, vbNullChar)
LSet strCryptBuffer = m_strInputData
' --------------------------------------------------------------------------' Encrypt the text data
' --------------------------------------------------------------------------If Not CBool(CryptEncrypt(lngHkey, ByVal 0&, ByVal 1&, ByVal 0&, _
strCryptBuffer, lngCryptLength, lngCryptBufLen)) The
n
MsgBox "Bytes required:" & CStr(lngCryptBufLen) & vbCrLf & vbCrLf & _
2: GetCipherType
3: GetCipherType
4: GetCipherType
5: GetCipherType
Else
MsgBox "Enhanced
=
=
=
=
CALG_RC2
CALG_DES
CALG_3DES
CALG_3DES_112
_
vbExclamation Or vbOKOnly, "Wrong Cipher Selection"
GetCipherType = 0
End Select
Else
Select Case intChoice
Case 1: ' Stream ciphers
GetCipherType = CALG_RC4
m_blnBlockCipher = False
***************************************************************************
Routine:
StringToByteArray
Description:
Parameters:
Returns:
Byte array
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------03-OCT-2000 Kenneth Ives kenaso@home.com
Modified and documented
***************************************************************************
'
'
'
'
'
--------------------------------------------------------------------------Convert each character in the data string to its ASCII numeric equivalent.
I use the VB function CByte() because sometimes the ASC() function returns
data that does not convert to a value of 0 to 255 cleanly.
--------------------------------------------------------------------------For lngIndex = 0 To lngLength - 1
bytBuffer(lngIndex) = CByte(Asc(Mid$(varInput, lngIndex + 1, 1)))
Next
***************************************************************************
Routine:
Rnd2
Description:
Parameters:
Returns:
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------26-JUN-1999 The VB2TheMax Team fbalena@vb2themax.com
Routine created
03-OCT-2000 Kenneth Ives kenaso@home.com
Modified and documented
24-JUL-2001 Kenneth Ives kenaso@home.com
Modified and documented
***************************************************************************
End Function
Private Function GetPassword(Optional blnUseDefaultPWD As Boolean = True) As Byt
e()
Attribute GetPassword.VB_Description = "Determines if the default password is to
be used or if one is to be created on the fly."
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
***************************************************************************
Routine:
GetPassword
Description:
NOTE:
Parameters:
Returns:
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------24-JUL-2001 Kenneth Ives kenaso@home.com
Wrote routine
09-SEP-2001 Kenneth Ives kenaso@home.com
Changed to a function routine. Now returns a password inside
a byte array.
***************************************************************************
--------------------------------------------------------------------------If the request is to use the default password then load each character
separately. This is faster and more difficult for a hacker to read the
default password. Create your own. This one is for demo purposes only.
--------------------------------------------------------------------------If blnUseDefaultPWD Then
' size the password array
ReDim abytPWord(20)
'
'
'
'
abytPWord(0) = CByte(Asc("u"))
abytPWord(1) = CByte(Asc("s"))
abytPWord(2) = CByte(Asc("E"))
abytPWord(3) = CByte(Asc("."))
abytPWord(4) = CByte(Asc("d"))
abytPWord(5) = CByte(Asc("e"))
abytPWord(6) = CByte(Asc("F"))
abytPWord(7) = CByte(Asc("a"))
abytPWord(8) = CByte(Asc("U"))
abytPWord(9) = CByte(Asc("L"))
abytPWord(10) = CByte(Asc("t"))
abytPWord(11) = CByte(Asc("-"))
abytPWord(12) = CByte(Asc("p"))
abytPWord(13) = CByte(Asc("a"))
abytPWord(14) = CByte(Asc("S"))
abytPWord(15) = CByte(Asc("s"))
abytPWord(16) = CByte(Asc("w"))
abytPWord(17) = CByte(Asc("O"))
abytPWord(18) = CByte(Asc("r"))
abytPWord(19) = CByte(Asc("d"))
Else
' Create a random generated password 20 characters long
' using printable characters
strPassword = CreateSaltValue(20, True)
' Initialize byte array
Erase abytPWord()
ReDim abytPWord(0)
***************************************************************************
Routine:
GetProvider
Description:
Returns:
===========================================================================
'
'
'
'
'
'
'
'
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------15-DEC-2000 Kenneth Ives kenaso@home.com
Wrote original
09-SEP-2001 Kenneth Ives kenaso@home.com
Fixed a bug when trying to acquire the enhanced provider.
***************************************************************************
--------------------------------------------------------------------------If no luck acquiring a provider handle then create default key container
using the current user's logon ID. Make sure this is not shared because
other users will have problems.
--------------------------------------------------------------------------If CBool(CryptAcquireContext(m_lngCryptContext, ByVal strTemp, _
ByVal strTemp, PROV_RSA_FULL, CRYPT_NEWKEYSET)) Then
GetProvider = True
Else
' Failed to aquire provider handle
strErrorMsg = "Error creating DEFAULT key container - " & CStr(Err.LastDll
Error)
MsgBox strErrorMsg, vbCritical Or vbOKOnly, "Cannot access CryptoAPI"
GetProvider = False
End If
End Function
Private Sub Class_Initialize()
'
'
'
'
'
'
'
'
'
'
'
'
'
'
***************************************************************************
Routine:
Class_Initialize
Description:
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------15-DEC-2000 Kenneth Ives kenaso@home.com
Wrote original
09-SEP-2001 Kenneth Ives kenaso@home.com
Modified and documented
***************************************************************************
***************************************************************************
Routine:
Class_Terminate
Description:
===========================================================================
DATE
NAME / eMAIL
DESCRIPTION
----------- -------------------------------------------------------------15-DEC-2000 Kenneth Ives kenaso@home.com
Modified and documented
***************************************************************************