CryptoSys API Library Manual

AES192_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 AES192_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 = AES192_HexMode(strOutput, strInput, strHexKey, bEncrypt, strMode, strHexIV)

C/C++ Syntax

long __stdcall AES192_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 128-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

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

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 48 hex characters long (i.e. representing exactly 24 bytes/192 bits). The initialization vector szHexIV must be exactly 32 hex characters long (i.e. representing the block size of exactly 16 bytes), except for ECB mode, where it is ignored (use ""). 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].

Example

    Dim nRet As Long
    Dim strOutput As String
    Dim strInput As String
    Dim strHexKey As String
    Dim sPlain As String
    Dim sCipher As String
    Dim strHexIV As String
    
' Encrypting 64 bytes (4 blocks) using AES-CBC with 192-bit key
    
    strHexKey = "56e47a38c5598974bc46903dba29034906a9214036b8a15b"
    strHexIV = "8ce82eefbea0da3c44699ed7db51b7d9"
    sPlain = "a0a1a2a3a4a5a6a7a8a9aaabacadaeaf" _
        & "b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" _
        & "c0c1c2c3c4c5c6c7c8c9cacbcccdcecf" _
        & "d0d1d2d3d4d5d6d7d8d9dadbdcdddedf"
    sCipher = "738237036dfdde9dda3374fa182600c5" _
        & "38d9187a0299725d0a7fdbe844d77578" _
        & "1539e401b5597cbbfa836efd22d998d2" _
        & "1605d8df340622417b911467b5e51a12" _
        
    strInput = sPlain
    ' Set strOutput to be same length as strInput
    strOutput = String(Len(strInput), " ")
    
    Debug.Print "KY=" & strHexKey
    Debug.Print "IV=" & strHexIV
    Debug.Print "PT=" & strInput
    ' Encrypt in one-off process
    nRet = AES192_HexMode(strOutput, strInput, strHexKey, ENCRYPT, "CBC", strHexIV)
    Debug.Print "CT=" & strOutput; nRet
    Debug.Print "OK=" & sCipher
    Debug.Assert (strOutput = sCipher)

    ' Decrypt to check
    strInput = strOutput
    nRet = AES192_HexMode(strOutput, strInput, strHexKey, DECRYPT, "CBC", strHexIV)
    Debug.Print "P'=" & strOutput; nRet
    Debug.Print "OK=" & sPlain
    Debug.Assert (strOutput = sPlain)

This should result in output as follows:

KY=56e47a38c5598974bc46903dba29034906a9214036b8a15b
IV=8ce82eefbea0da3c44699ed7db51b7d9
PT=a0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7
b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d
1d2d3d4d5d6d7d8d9dadbdcdddedf
CT=738237036DFDDE9DDA3374FA182600C538D9187A0299725D
0A7FDBE844D775781539E401B5597CBBFA836EFD22D998D2160
5D8DF340622417B911467B5E51A12 0 
OK=738237036dfdde9dda3374fa182600c538d9187a0299725d
0a7fdbe844d775781539e401b5597cbbfa836efd22d998d2160
5d8df340622417b911467b5e51a12
P'=A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7
B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D
1D2D3D4D5D6D7D8D9DADBDCDDDEDF 0 
OK=a0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7
b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d
1d2d3d4d5d6d7d8d9dadbdcdddedf

See Also

AES192_Hex

[Contents] [Index]

[PREV: AES192_Hex...]   [Contents]   [Index]   
   [NEXT: AES192_Init...]

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