Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

January 17, 2008

Matching PHP 5.2.5 AES Encryption with ActiveX AES Encryption

Here’s a PHP 5.2.5 script using mcrypt to do 128-bit AES encryption in ECB mode.
The matching Chilkat Encryption ActiveX code (in VBScript) follows:

$cc = 'my secret text';
$key = '1234567890123456';
# Technically, no IV is required for ECB mode, but PHP demands it anyway.
$iv =  '1234567890123456';
$length = strlen($cc);
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'','ecb','');
mcrypt_generic_init($cipher, $key, $iv);
$encrypted = base64_encode(mcrypt_generic($cipher,$cc));
mcrypt_generic_init($cipher, $key, $iv);
$decrypted = mdecrypt_generic($cipher,base64_decode($encrypted));
echo "encrypted: " . $encrypted;
echo "\n";
echo "decrypted: " . substr($decrypted, 0, $length) . "\n";

The PHP script output is:
encrypted: u6UmJ08GrX7zRCzE+/pksQ==
decrypted: my secret text

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.txt", True)
set crypt = CreateObject("Chilkat.Crypt2")
success = crypt.UnlockComponent("Anything for 30-day trial")
If (success <> 1) Then
    MsgBox "Crypt component unlock failed"
End If
crypt.CryptAlgorithm = "aes"
crypt.CipherMode = "ecb"
crypt.KeyLength = 128
crypt.PaddingScheme = 3
crypt.SetEncodedKey "1234567890123456","ascii"
crypt.EncodingMode = "base64"
text = "my secret text"
'  Encrypt a string and return the binary encrypted data
'  in a base-64 encoded string.
encText = crypt.EncryptStringENC(text)
'  Decrypt and show the original string:
decryptedText = crypt.DecryptStringENC(encText)
' This gets rid of the NULL padding chars...
decryptedText = crypt.TrimEndingWith(decryptedText," ")

The VBScript output is:
my secret text

Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.