PHP mcrypt // Chilkat AES 加密 -- 集成

发布于 2024-09-03 09:54:28 字数 1450 浏览 10 评论 0原文

我正在尝试使用 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 中模拟这些默认值。

提前非常感谢。

I'm trying to decrypt a string using PHP which was encrypted using a Chilkat library.

VB Encryption:

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 Decryption:

$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";

The output is garbage ... any ideas? I'm not sure exactly what the default IV and Padding settings that Chilkat uses, nor am I sure how to emulate those default values in PHP.

Thanks much in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们的影子 2024-09-10 09:54:28

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

my guess: try md5($key, true) instead of md5($key).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文