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.
Public Declare Function AES192_Hex Lib "diCryptoSys.dll"
(ByVal strOutput As String, ByVal strInput As String, ByVal strHexKey As String,
ByVal bEncrypt As Boolean) As Long
nRet = AES192_Hex(strOutput, strInput, strHexKey, bEncrypt)
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.
long _stdcall AES192_Hex(char *lpszOutput, const char *lpszInput,
const char *lpszKey, int bEncrypt);
Long: If successful, the return value is 0;
otherwise it returns a non-zero error code.
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 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 = AES192_HexMode(strOutput, strInput, strHexKey, bEncrypt, "ECB", 0)
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.2 AES-192 (Nk=6, Nr=12)
'PLAINTEXT: 00112233445566778899aabbccddeeff
'KEY: 000102030405060708090a0b0c0d0e0f1011121314151617
strHexKey = "000102030405060708090a0b0c0d0e0f1011121314151617"
sPlain = "00112233445566778899aabbccddeeff"
sCipher = "dda97ca4864cdfe06eaf70a0ec0d7191"
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 = AES192_Hex(strOutput, strInput, strHexKey, ENCRYPT)
Debug.Print "CT="; strOutput; nRet
Debug.Print "OK="; sCipher
' Now decrypt back to plain text
strInput = strOutput
nRet = AES192_Hex(strOutput, strInput, strHexKey, DECRYPT)
Debug.Print "P'="; strOutput; nRet
This should result in output as follows:
KY=000102030405060708090a0b0c0d0e0f1011121314151617 PT=00112233445566778899aabbccddeeff CT=DDA97CA4864CDFE06EAF70A0EC0D7191 0 OK=dda97ca4864cdfe06eaf70a0ec0d7191 P'=00112233445566778899AABBCCDDEEFF 0