【问题标题】:PHP mcrypt // Chilkat AES encryption -- integrationPHP mcrypt // Chilkat AES 加密——集成
【发布时间】:2011-02-23 20:41:13
【问题描述】:

我正在尝试使用 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";

输出是垃圾......有什么想法吗?我不确定 Chilkat 使用的默认 IV 和 Padding 设置到底是什么,也不确定如何在 PHP 中模拟这些默认值。

非常感谢。

【问题讨论】:

    标签: php aes mcrypt chilkat


    【解决方案1】:

    我的猜测:试试 md5($key, true) 而不是 md5($key)。

    【讨论】:

      猜你喜欢
      • 2011-09-18
      • 2014-09-12
      • 2014-06-28
      • 2014-02-06
      • 2023-03-23
      • 2014-12-24
      • 1970-01-01
      • 2012-11-06
      • 1970-01-01
      相关资源
      最近更新 更多