CryptoSys API Library Manual

TDEA_HexMode

Encrypts or decrypts data represented as a hexadecimal string using a specified mode. The key and initialization vector are represented as a hexadecimal string.

VBA/VB6 Syntax

Public Declare Function TDEA_HexMode Lib "diCryptoSys.dll" (ByVal strOutput As String, ByVal strInput As String, ByVal strHexKey As String, ByVal bEncrypt As Boolean, ByVal strMode As String, ByVal strHexIV As String) As Long

nRet = TDEA_HexMode(strOutput, strInput, strHexKey, bEncrypt, strMode, strHexIV)

C/C++ Syntax

long __stdcall TDEA_HexMode(char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV);

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.
szMode
[in] specifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
szIV
[in] containing the initialization vector (IV) in hexadecimal.

Returns (VBA/C)

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

.NET Equivalent

Tdea.Encrypt Method (String, String, Mode, String)
Tdea.Decrypt Method (String, String, Mode, String)

COM/ASP Equivalent

tdea.HexMode
Public Function HexMode(ByVal strInput As String, ByVal strHexKey As String, ByVal bEncrypt As Boolean, ByVal strMode As String, ByVal strHexIV As String) As String

See tdea.HexMode.

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 szHexKey must be exactly 48 hex characters long (i.e. representing exactly 24 bytes). The initialization vector string szIV must be exactly 16 hex characters long (i.e. representing exactly 8 bytes) unless szMode is ECB, in which case szIV is ignored (use ""). Valid hexadecimal characters are [0-9A-Fa-f]. 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.

Example

    Dim nRet As Long
    Dim strOutput As String
    Dim strInput As String
    Dim strKey As String
    Dim strIV As String
    Dim bEncrypt As Boolean
    Dim sCorrect As String

    strInput = "5468697320736F6D652073616D706520636F6E74656E742E0808080808080808"
    strKey = "737C791F25EAD0E04629254352F7DC6291E5CB26917ADA32"
    strIV = "B36B6BFB6231084E"
    sCorrect = "d76fd1178fbd02f84231f5c1d2a2f74a4159482964f675248254223daf9af8e4"
    ' Set strOutput to be same length as strInput
    strOutput = String(Len(strInput), " ")

    Debug.Print "KY=" & strKey
    Debug.Print "PT=" & strInput
    nRet = TDEA_HexMode(strOutput, strInput, strKey, True, "CBC", strIV)
    Debug.Print "CT=" & strOutput; nRet
    Debug.Print "OK=" & sCorrect

    strInput = strOutput
    nRet = TDEA_HexMode(strOutput, strInput, strKey, DECRYPT, "CBC", strIV)
    Debug.Print "P'=" & strOutput; nRet

This should result in output as follows:

KY=737C791F25EAD0E04629254352F7DC6291E5CB26917ADA32
PT=5468697320736F6D652073616D706520636F6E74656E742E0808080808080808
CT=D76FD1178FBD02F84231F5C1D2A2F74A4159482964F675248254223DAF9AF8E4 0
OK=d76fd1178fbd02f84231f5c1d2a2f74a4159482964f675248254223daf9af8e4
P'=5468697320736F6D652073616D706520636F6E74656E742E0808080808080808 0

See Also

TDEA_Hex

[Contents] [Index]

[PREV: TDEA_Hex...]   [Contents]   [Index]   
   [NEXT: TDEA_Init...]

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