CryptoSys API Library Manual

DES_Hex

Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation. The process is carried out in one step in Electronic Codebook (EBC) mode.

@deprecated use DES_HexMode with strMode="ECB".

VBA/VB6 Syntax

Public Declare Function DES_Hex Lib "diCryptoSys.dll" (ByVal strOutput As String, ByVal strInput As String, ByVal strKey As String, ByVal bEncrypt As Boolean) As Long

nRet = DES_Hex(strOutput, strInput, strKey, bEncrypt)

C/C++ Syntax

long __stdcall DES_Hex(char *szOutput, const char *szInput, const char *szKey, int fEncrypt);

Parameters

szOutput
[out] of sufficient length to receive the output.
szInput
[in] containing the input data in hexadecimal.
szKey
[in] containing the key in hexadecimal.
fEncrypt
[in] direction flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.

Returns (VBA/C)

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

.NET Equivalent

Des.Encrypt Method (String, String, Mode, String)
Des.Decrypt Method (String, String, Mode, String)
with mode=Mode.ECB.

Remarks

The length of the input string szInput 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. The key string szKey must be exactly 16 hex characters long (i.e. representing exactly 8 bytes). The parity bit is ignored. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different. Valid hexadecimal characters are [0-9A-Fa-f].

Example

    Dim nRet As Long
    Dim strOutput As String
    Dim strInput As String
    Dim strKey As String
    Dim sCorrect As String

    ' "Now is t" in hex
    strInput = "4e6f772069732074"
    strKey = "0123456789abcdef"
    sCorrect = "3fa40e8a984d4815"
    ' Set strOutput to be same length as strInput
    strOutput = String(Len(strInput), " ")

    Debug.Print "KY=" & strKey
    Debug.Print "PT=" & strInput
    ' Encrypt in one-off process
    nRet = DES_Hex(strOutput, strInput, strKey, ENCRYPT)
    Debug.Print "CT=" & strOutput
    Debug.Print "OK=" & sCorrect

    ' Now decrypt back to plain text
    strInput = strOutput
    nRet = DES_Hex(strOutput, strInput, strKey, DECRYPT)
    Debug.Print "P'=" & strOutput

This should result in output as follows:

KY=0123456789abcdef
PT=4e6f772069732074
CT=3FA40E8A984D4815
OK=3fa40e8a984d4815
P'=4E6F772069732074

See Also

DES_HexMode

[Contents] [Index]

[PREV: DES_Final...]   [Contents]   [Index]   
   [NEXT: DES_HexMode...]

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