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.
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)
String of sufficient length to receive the output.String containing the input data in hexadecimal.String containing the key in hexadecimal.Boolean direction flag:
set as True to encrypt or False
to decrypt.String specifying the confidentiality mode:String containing the initialization vector (IV)
in hexadecimal.
long _stdcall AES192_HexMode(char *lpszOutput, const char *lpszInput,
const char *lpszKey, int bEncrypt, const char *lpszMode, const char *lpszIV);
Long: If successful, the return value is 0;
otherwise it returns a non-zero error code.
Aes192.Encrypt Method (String, String, Mode, String)
Aes192.Decrypt Method (String, String, Mode, String)
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 48 hex characters long (i.e. representing exactly 24 bytes/192 bits).
The initialization vector strHexIV
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 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].
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