Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
AES Encryption to Match PHP's Mcrypt ExtensionDemonstrates how to match AES encryption results with PHP's mcrypt extension. Please refer to this discussion about PHP AES Encryption. The code here matches the PHP mcrypt results on that page.
LOCAL loCrypt LOCAL lnSuccess LOCAL lcIvAscii LOCAL lcKeyAscii LOCAL lcPlainText LOCAL lcCipherText loCrypt = CreateObject('Chilkat.Crypt2') lnSuccess = loCrypt.UnlockComponent("Anything for 30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX("Crypt component unlock failed") QUIT ENDIF * AES is also known as Rijndael. loCrypt.CryptAlgorithm = "aes" * CipherMode may be "ecb" or "cbc" loCrypt.CipherMode = "cbc" * KeyLength may be 128, 192, 256 loCrypt.KeyLength = 256 * Pad with NULL bytes (PHP pads with NULL bytes) loCrypt.PaddingScheme = 3 * EncodingMode specifies the encoding of the output for * encryption, and the input for decryption. * It may be "hex", "url", "base64", or "quoted-printable". loCrypt.EncodingMode = "hex" lcIvAscii = "1234567890123456" loCrypt.SetEncodedIV(lcIvAscii,"ascii") * The secret key must equal the size of the key. For * 256-bit encryption, the binary secret key is 32 bytes. * For 128-bit encryption, the binary secret key is 16 bytes. lcKeyAscii = "12345678901234561234567890123456" loCrypt.SetEncodedKey(lcKeyAscii,"ascii") lcPlainText = "The quick brown fox jumped over the lazy dog" lcCipherText = loCrypt.EncryptStringENC(lcPlainText) =MESSAGEBOX(lcCipherText) * Do 128-bit AES encryption: loCrypt.KeyLength = 128 lcKeyAscii = "1234567890123456" loCrypt.SetEncodedKey(lcKeyAscii,"ascii") lcCipherText = loCrypt.EncryptStringENC(lcPlainText) =MESSAGEBOX(lcCipherText) * ------- * Results * ------- * You may use these as test vectors for testing your AES implementations... * * ------------------------ * 256-bit key, CBC mode * ------------------------ * IV = '1234567890123456' * (hex: 31323334353637383930313233343536) * Key = '12345678901234561234567890123456' * (hex: 3132333435363738393031323334353631323334353637383930313233343536) * PlainText: * 'The quick brown fox jumped over the lazy dog' // CipherText(hex): * 2fddc3abec692e1572d9b7d629172a05caf230bc7c8fd2d26ccfd65f9c54526984f7cb1c4326ef058cd7bee3967299e3 * * ------------------------ * 128-bit key, CBC mode * ------------------------ * IV = '1234567890123456' * (hex: 31323334353637383930313233343536) * Key = '1234567890123456' * (hex: 31323334353637383930313233343536) * PlainText: * 'The quick brown fox jumped over the lazy dog' // CipherText(hex): * f78176ae8dfe84578529208d30f446bbb29a64dc388b5c0b63140a4f316b3f341fe7d3b1a3cc5113c81ef8dd714a1c99 |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser