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.

VB6/VBA 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)

Parameters

strOutput
[out] String of sufficient length to receive the output.
strInput
[in] String containing the input data in hexadecimal.
strHexKey
[in] String containing the key in hexadecimal.
bEncrypt
[in] Boolean direction flag: set as True to encrypt or False to decrypt.

C/C++ Syntax

long _stdcall AES256_Hex(char *lpszOutput, const char *lpszInput, const char *lpszKey, int bEncrypt);

Returns (VB6/C)

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

Remarks

The length of the input string strInput must be a multiple of 32 hex characters long (i.e. representing a multiple of the block size of 16 bytes). The key string strHexKey must be exactly 64 hex characters long (i.e. representing exactly 32 bytes/256 bits). The output string strOutput must be set up with at least the same number of characters as the input string before calling. The variables strOutput and strInput 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]

[HOME]   [NEXT: AES256_HexMode...]

Copyright © 2001-11 D.I. Management Services Pty Ltd. All rights reserved.