PHP mcrypt // Chilkat AES шифрование - интеграция - PullRequest
0 голосов
/ 25 мая 2010

Я пытаюсь расшифровать строку с помощью PHP, которая была зашифрована с помощью библиотеки Chilkat.

VB Шифрование:

Dim password As String
password = "foobar"

crypt.CryptAlgorithm = "aes"
crypt.CipherMode = "cbc"
crypt.KeyLength = 128

'  Generate a binary secret key from a password string
'  of any length.  For 128-bit encryption, GenEncodedSecretKey
'  generates the MD5 hash of the password and returns it
'  in the encoded form requested.  The 2nd param can be
'  "hex", "base64", "url", "quoted-printable", etc.
Dim hexKey As String
hexKey = crypt.GenEncodedSecretKey(password,"hex")
crypt.SetEncodedKey hexKey,"hex"

crypt.EncodingMode = "base64"
Dim text As String
text = "The quick brown fox jumped over the lazy dog."

'  Encrypt a string and return the binary encrypted data
'  in a base-64 encoded string.
Dim encText As String
encText = crypt.EncryptStringENC(text)

Расшифровка PHP:

$filename = "test.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
// remove newlines, etc
$contents = rtrim( $contents );
// remove base64 encoding
$contents = base64_decode( $contents );

$key = "foobar";
// make a hex of this key
$key = md5( $key );
// notice the iv is NOT set
$crypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $contents, MCRYPT_MODE_CBC);
echo "Decrypted: $crypttext \n";

Вывод мусор ... есть идеи? Я не уверен, какие именно настройки IV и Padding по умолчанию использует Chilkat, и не уверен, как эмулировать эти значения по умолчанию в PHP.

Большое спасибо заранее.

1 Ответ

0 голосов
/ 14 августа 2010

мое предположение: попробуйте md5 ($ key, true) вместо md5 ($ key).

...