CryptoSys API Library Manual

AES256_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 AES256_HexMode with strMode="ECB".

VBA/VB6 Syntax

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

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

C/C++ Syntax

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

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

Remarks

The length of the input string szInput must be a multiple of 32 hex characters long (i.e. representing a multiple of the block size of 16 bytes). The key string szHexKey must be exactly 64 hex characters long (i.e. representing exactly 32 bytes/256 bits). 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 = AES256_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.3 AES-256 (Nk=8, Nr=14)
'PLAINTEXT: 00112233445566778899aabbccddeeff
'KEY: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
    strHexKey = _
    "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
    sPlain = "00112233445566778899aabbccddeeff"
    sCipher = "8EA2B7CA516745BFEAFC49904B496089"
    
    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 = AES256_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 = AES256_Hex(strOutput, strInput, strHexKey, DECRYPT)
    Debug.Print "P'=" & strOutput; nRet
    Debug.Assert (strOutput = sPlain)

This should result in output as follows:

KY=000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
PT=00112233445566778899aabbccddeeff
CT=8EA2B7CA516745BFEAFC49904B496089 0 
OK=8EA2B7CA516745BFEAFC49904B496089
P'=00112233445566778899AABBCCDDEEFF 0 

See Also

AES256_HexMode

[Contents] [Index]

[PREV: AES256_Final...]   [Contents]   [Index]   
   [NEXT: AES256_HexMode...]

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