CryptoSys API Library Manual

AES128_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 AES128_HexMode with strMode="ECB".

VBA/VB6 Syntax

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

nRet = AES128_Hex(strOutput, strInput, strHexKey, bEncrypt)

C/C++ Syntax

long __stdcall AES128_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

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

Remarks

The length of the input string szInput should be a multiple of 32 hex characters long (i.e. representing a multiple of 16 bytes). The key string szHexKey must be exactly 32 hex characters long (i.e. representing exactly 16 bytes). 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].

This function is equivalent to

nRet = AES128_HexMode(strOutput, strInput, strHexKey, bEncrypt, "ECB", 0)

Example

This example is taken from FIPS 197 Appendix C.

    Dim nRet As Long
    Dim strOutput As String
    Dim strInput As String
    Dim strHexKey As String
    Dim sPlain As String
    Dim sCipher As String
    
    'FIPS-197
    'C.1 AES-128 (Nk=4, Nr=10)
    'PLAINTEXT: 00112233445566778899aabbccddeeff
    'KEY: 000102030405060708090a0b0c0d0e0f
    strHexKey = "000102030405060708090a0b0c0d0e0f"
    sPlain = "00112233445566778899aabbccddeeff"
    sCipher = "69c4e0d86a7b0430d8cdb78070b4c55a"
    
    strInput = sPlain
    ' Set strOutput to be same length as strInput
    strOutput = String(Len(strInput), " ")
    
    Debug.Print "KY=" & strHexKey
    Debug.Print "PT=" & strInput
    ' Encrypt in one-off process
    nRet = AES128_Hex(strOutput, strInput, strHexKey, ENCRYPT)
    Debug.Print "CT=" & strOutput & nRet
    Debug.Print "OK=" & sCipher
    Debug.Assert (strOutput = sCipher)
    
    ' Now decrypt back to plain text
    strInput = strOutput
    nRet = AES128_Hex(strOutput, strInput, strHexKey, DECRYPT)
    Debug.Print "P'=" & strOutput; nRet
    Debug.Assert (strOutput = sPlain)

This should result in output as follows:

KY=000102030405060708090a0b0c0d0e0f
PT=00112233445566778899aabbccddeeff
CT=69C4E0D86A7B0430D8CDB78070B4C55A 0 
OK=69c4e0d86a7b0430d8cdb78070b4c55a
P'=00112233445566778899AABBCCDDEEFF 0 

See Also

AES128_HexMode

[Contents] [Index]

[PREV: AES128_Final...]   [Contents]   [Index]   
   [NEXT: AES128_HexMode...]

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