CryptoSys API Library Manual

DES_UpdateHex

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().

VBA/VB6 Syntax

Public Declare Function DES_UpdateHex Lib "diCryptoSys.dll" (ByVal hContext As Long, ByVal strHexString As String) As Long

nRet = DES_UpdateHex(hContext, strHexString)

C/C++ Syntax

long __stdcall DES_UpdateHex(long hContext, char *szHexData);

Parameters

hContext
[in] handle to the DES context set up by an earlier call to DES_Init() or DES_InitHex().
szHexData
[in,out] containing input in hexadecimal format to be processed by the DES function and to receive the output.

Returns (VBA/C)

If successful, the return value is 0; otherwise it returns a non-zero error code.

.NET Equivalent

Des.Update Method (String)

Remarks

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.

Example

    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

See Also

DES_Init DES_InitHex DES_Update DES_Final

[Contents] [Index]

[PREV: DES_Update...]   [Contents]   [Index]   
   [NEXT: GCM_Decrypt...]

Copyright © 2001-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-01-07T07:42:00Z.