CryptoSys API Library Manual

Example: Aes128.Decrypt  Aes128.Encrypt  (2)

[VB6 equivalent: AES128_Bytes]

Dim abBlock() As Byte
Dim abKey() As Byte
Dim abPlain() As Byte
Dim abCipher() As Byte

'FIPS-197
'C.1 AES-128 (Nk=4, Nr=10)
'PLAINTEXT: 00112233445566778899aabbccddeeff
'KEY: 000102030405060708090a0b0c0d0e0f

' Convert input to bytes
abKey = Cnv.FromHex("000102030405060708090a0b0c0d0e0f")
abPlain = Cnv.FromHex("00112233445566778899aabbccddeeff")
abCipher = Cnv.FromHex("69c4e0d86a7b0430d8cdb78070b4c55a")

abBlock = abPlain
Console.WriteLine("KY=" & Cnv.ToHex(abKey))
Console.WriteLine("PT=" & Cnv.ToHex(abBlock))
' Encrypt in one-off process
abBlock = Aes128.Encrypt(abBlock, abKey, Mode.ECB, Nothing)
Console.WriteLine("CT=" & Cnv.ToHex(abBlock))
Console.WriteLine("OK=" & Cnv.ToHex(abCipher))
Debug.Assert(Cnv.ToHex(abBlock) = Cnv.ToHex(abCipher))

' Now decrypt back to plain text
abBlock = Aes128.Decrypt(abBlock, abKey, Mode.ECB, Nothing)
Console.WriteLine("P'=" & Cnv.ToHex(abBlock))
Debug.Assert(Cnv.ToHex(abBlock) = Cnv.ToHex(abPlain))

See Also:
Aes128.Decrypt Method (Byte[], Byte[], Mode, Byte[])
Aes128.Encrypt Method (Byte[], Byte[], Mode, Byte[])

[Contents] [Index]

[PREV: Example: Aes128.Decrypt ...]   [Contents]   [Index]   
   [NEXT: Example: Aes128.Decrypt ...]

Copyright © 2001-23 D.I. Management Services Pty Ltd. All rights reserved. Generated 2023-05-20T13:01:10Z.