Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode.
@deprecated use
AES256_BytesMode
with strMode="ECB"
.
Public Declare Function AES256_Bytes Lib "diCryptoSys.dll"
(ByRef lpOutput As Byte, ByRef lpData As Byte, ByVal nDataLen As Long, ByRef lpKey As Byte,
ByVal bEncrypt As Boolean) As Long
nRet = AES256_Bytes(lpOutput(0), abData(0), nDataLen, abKey(0), bEncrypt)
' Note the "(0)" after the byte array parameters
long __stdcall AES256_Bytes(unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, int fEncrypt);
If successful, the return value is 0; otherwise it returns a non-zero error code.
Aes256.Encrypt Method (Byte[], Byte[], Mode, Byte[])
Aes256.Decrypt Method (Byte[], Byte[], Mode, Byte[])
with mode=Mode.ECB
.
The input array lpData 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 32 bytes long (i.e. 256 bits). The output array lpOutput must be at least as long as the input array. lpOutput and lpData may be the same.
This function is equivalent to
nRet = AES256_BytesMode(lpOutput(0), abData(0), nDataLen, abKey(0), bEncrypt, "ECB", 0)
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.3 AES-256 (Nk=8, Nr=14) 'PLAINTEXT: 00112233445566778899aabbccddeeff 'KEY: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f ' round[14].output 8ea2b7ca516745bfeafc49904b496089 strHexKey = _ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" sPlain = "00112233445566778899aabbccddeeff" sCipher = "8ea2b7ca516745bfeafc49904b496089" ' 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 = AES256_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 = AES256_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=000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F PT=00112233445566778899AABBCCDDEEFF CT=8EA2B7CA516745BFEAFC49904B496089 OK=8EA2B7CA516745BFEAFC49904B496089 P'=00112233445566778899AABBCCDDEEFF