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:
<?php
$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_deinit($cipher);
mcrypt_generic_init($cipher, $key, $iv);
$decrypted = mdecrypt_generic($cipher,base64_decode($encrypted));
mcrypt_generic_deinit($cipher);
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"
WScript.Quit
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)
outFile.WriteLine(encText)
' Decrypt and show the original string:
decryptedText = crypt.DecryptStringENC(encText)
' This gets rid of the NULL padding chars...
decryptedText = crypt.TrimEndingWith(decryptedText," ")
outFile.WriteLine(decryptedText)
outFile.Close
The VBScript output is:
u6UmJ08GrX7zRCzE+/pksQ==
my secret text