Carries out the DES transformation function on a hexadecimal string
according to the direction
and mode set up by an earlier call to DES_Init() or DES_InitHex().
Public Declare Function DES_UpdateHex Lib "diCryptoSys.dll"
(ByVal hContext As Long, ByVal strHexString As String) As Long
nRet = DES_UpdateHex(hContext, strHexString)
long __stdcall DES_UpdateHex(long hContext, char *szHexData);
DES_Init() or DES_InitHex().If successful, the return value is 0; otherwise it returns a non-zero error code.
Des.Update Method (String)
szHexString must be a multiple of 16 hex characters long (i.e. representing a multiple of 8 bytes). If not, an error code will be returned. Valid hexadecimal characters are [0-9A-Fa-f]. Note that the output overwrites the input. szHexString must be a variable that can receive the output, not a constant.
Dim nRet As Long
Dim hContext As Long
Dim strKey As String
Dim strHexString As String
Dim sCorrect As String
strKey = "0123456789abcdef"
Debug.Print "KY=" & strKey
' Initialise the context
hContext = DES_InitHex(strKey, True, "ECB", "")
If hContext = 0 Then
' Always check for error
MsgBox "Unable to initialise DES context", vbCritical
Exit Function
End If
strHexString = "4e6f772069732074"
Debug.Print "PT=" & strHexString
nRet = DES_UpdateHex(hContext, strHexString)
Debug.Print "CT=" & strHexString
Debug.Print "OK=" & "3fa40e8a984d4815"
strHexString = "68652074696d6520666f7220616c6c20"
Debug.Print "PT=" & strHexString
nRet = DES_UpdateHex(hContext, strHexString)
Debug.Print "CT=" & strHexString
Debug.Print "OK=" & "6a271787ab8883f9893d51ec4b563b53"
nRet = DES_Final(hContext)
This should result in output as follows:
KY=0123456789abcdef PT=4e6f772069732074 CT=3FA40E8A984D4815 OK=3fa40e8a984d4815 PT=68652074696d6520666f7220616c6c20 CT=6A271787AB8883F9893D51EC4B563B53 OK=6a271787ab8883f9893d51ec4b563b53
DES_Init
DES_InitHex
DES_Update
DES_Final