CryptoSys API Library Manual

TDEA_Bytes

Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode.

@deprecated use TDEA_BytesMode with strMode="ECB".

VBA/VB6 Syntax

Public Declare Function TDEA_Bytes Lib "diCryptoSys.dll" (ByRef lpOutput As Byte, ByRef lpData As Byte, ByVal nDataLen As Long, ByRef lpKey As Byte, ByVal bEncrypt As Boolean) As Long

nRet = TDEA_Bytes(lpOutput(0), abData(0), nDataLen, abKey(0), bEncrypt) ' Note the "(0)" after the byte array parameters

C/C++ Syntax

long __stdcall TDEA_Bytes(unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, int fEncrypt);

Parameters

lpOutput
[out] array of sufficient length to receive the output.
lpInput
[in] array containing the input data.
nBytes
[in] equal to length of the input data in bytes.
lpKey
[in] array containing the key.
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

Tdea.Encrypt Method (Byte[], Byte[], Mode, Byte[])
Tdea.Decrypt Method (Byte[], Byte[], Mode, Byte[])
with mode=Mode.ECB.

Remarks

The input data lpData must be an exact multiple of 8 bytes long. If not, an error code will be returned. The key lpKey must be exactly 24 bytes long. The output array lpOutput must be at least nDataLen bytes long. lpOutput and lpData may be the same.

Example

    Dim nRet As Long
    Dim strInput As String
    Dim strKey As String
    Dim sCorrect As String
    Dim abKey() As Byte
    Dim lpOutput() As Byte
    Dim abData() As Byte
    Dim nDataLen As Long
    
    ' Define test vectors in hex
    strKey = "0123456789abcdeffedcba987654321089abcdef01234567"
    strInput = "0123456789abcde70123456789abcde7"
    sCorrect = "de0b7c06ae5e0ed5de0b7c06ae5e0ed5"
    
    ' Convert to byte arrays and compute lengths
    abKey = cnvBytesFromHexStr(strKey)
    abData = cnvBytesFromHexStr(strInput)
    nDataLen = Len(strInput) \ 2
    
    ' Dimension array for output
    ReDim lpOutput(nDataLen - 1)
    
    Debug.Print "KY=" & cnvHexStrFromBytes(abKey)
    Debug.Print "PT=" & cnvHexStrFromBytes(abData)
    ' Encrypt in one-off process
    nRet = TDEA_Bytes(lpOutput(0), abData(0), nDataLen, abKey(0), ENCRYPT)
    Debug.Print "CT=" & cnvHexStrFromBytes(lpOutput), nRet
    Debug.Print "OK=" & sCorrect
    Debug.Assert (sCorrect = cnvHexStrFromBytes(lpOutput))
    
    ' Now decrypt back
    nRet = TDEA_Bytes(abData(0), lpOutput(0), nDataLen, abKey(0), DECRYPT)
    Debug.Print "P'=" & cnvHexStrFromBytes(abData), nRet
    Debug.Assert (strInput = cnvHexStrFromBytes(abData))

This should result in output as follows:

KY=0123456789ABCDEFFEDCBA987654321089ABCDEF01234567
PT=0123456789ABCDE70123456789ABCDE7
CT=DE0B7C06AE5E0ED5DE0B7C06AE5E0ED5        0 
OK=de0b7c06ae5e0ed5de0b7c06ae5e0ed5
P'=0123456789ABCDE70123456789ABCDE7        0 

See Also

TDEA_BytesMode

[Contents] [Index]

[PREV: TDEA_B64Mode...]   [Contents]   [Index]   
   [NEXT: TDEA_BytesMode...]

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