CryptoSys API Library Manual

AES192_Bytes

AES192_Bytes encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode.

VB6/VBA Syntax

Public Declare Function AES192_Bytes Lib "diCryptoSys.dll" (ByRef abOutput As Byte, ByRef abData As Byte, ByVal nDataLen As Long, ByRef abKey As Byte, ByVal bEncrypt As Boolean) As Long

nRet = AES192_Bytes(abOutput(0), abData(0), nDataLen, abKey(0), bEncrypt)

Parameters

abOutput
[out] Byte array of sufficient length to receive the output.
abData
[in] Byte array containing the input data.
nDataLen
[in] Long equal to length of the input data in bytes.
abKey
[in] Byte array containing the key.
bEncrypt
[in] Boolean direction flag: set as True to encrypt or False to decrypt.

C/C++ Syntax

long _stdcall AES192_Bytes(unsigned char *output, const unsigned char *input, long nbytes, const unsigned char *key, int bEncrypt);

Returns (VB6/C)

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

Remarks

The input array abData must be a multiple of the block size of 16 bytes long. If not, an error code will be returned. The key array abKey() must be exactly 24 bytes (i.e. 192 bits) long. The output array abOutput must be at least as long as the input array. abOutput and abData may be the same. Note the (0) after the byte array variables.

This function is equivalent to

nRet = AES192_BytesMode(abOutput(0), abData(0), nDataLen, abKey(0), bEncrypt, "ECB", 0)

Example

    Dim nRet As Long
    Dim strHexKey As String
    Dim sPlain As String
    Dim sCipher As String
    Dim abBlock() As Byte
    Dim abKey() As Byte
    Dim abPlain() As Byte
    Dim abCipher() As Byte
    Dim nBytes As Long
    
    'FIPS-197
    'C.2 AES-192 (Nk=6, Nr=12)
    'PLAINTEXT: 00112233445566778899aabbccddeeff
    'KEY: 000102030405060708090a0b0c0d0e0f1011121314151617
    strHexKey = "000102030405060708090a0b0c0d0e0f1011121314151617"
    sPlain = "00112233445566778899aabbccddeeff"
    sCipher = "dda97ca4864cdfe06eaf70a0ec0d7191"
    
    ' Convert input to bytes
    abKey = cnvBytesFromHexStr(strHexKey)
    abPlain = cnvBytesFromHexStr(sPlain)
    abCipher = cnvBytesFromHexStr(sCipher)
    
    abBlock = abPlain
    nBytes = UBound(abBlock) - LBound(abBlock) + 1
    Debug.Print "KY="; cnvHexStrFromBytes(abKey)
    Debug.Print "PT="; cnvHexStrFromBytes(abBlock)
    ' Encrypt in one-off process
    nRet = AES192_Bytes(abBlock(0), abBlock(0), nBytes, abKey(0), ENCRYPT)
    Debug.Print "CT="; cnvHexStrFromBytes(abBlock)
    Debug.Print "OK="; cnvHexStrFromBytes(abCipher)
    Debug.Assert (StrConv(abBlock, vbUnicode) = StrConv(abCipher, vbUnicode))
    
    ' Now decrypt back to plain text
    nRet = AES192_Bytes(abBlock(0), abBlock(0), nBytes, abKey(0), DECRYPT)
    Debug.Print "P'="; cnvHexStrFromBytes(abBlock)
    Debug.Assert (StrConv(abBlock, vbUnicode) = StrConv(abPlain, vbUnicode))

This should result in output as follows:

KY=000102030405060708090A0B0C0D0E0F1011121314151617
PT=00112233445566778899AABBCCDDEEFF
CT=DDA97CA4864CDFE06EAF70A0EC0D7191
OK=DDA97CA4864CDFE06EAF70A0EC0D7191
P'=00112233445566778899AABBCCDDEEFF

See Also

AES192_BytesMode

[Contents] [Index]

[HOME]   [NEXT: AES192_BytesMode...]

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