在 JavaScript 中解密 PHP AES/CBC 加密字符串

发布于 2024-12-14 00:36:07 字数 567 浏览 4 评论 0原文

我真的很疯狂地试图用以下代码片段在 JavaScript 中解密用 PHP 加密的字符串:

function myencrypt($str) {
    $iv = '1234567890abcdef';
    $key = 'abcdef1234567890';

    $td = mcrypt_module_open('rijndael-128', '', 'cbc', $iv);
    mcrypt_generic_init($td, $key, $iv);
    $encrypted = mcrypt_generic($td, $str);

    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);

    return bin2hex($encrypted);
}

我尝试过 SlowAES、gibberish-aes 和其他一些可用的 JS 库,但总是无法正确解密单个字符串。

我也在 SO 中进行了广泛的搜索,但无法找到适合我的情况的解决方案。

任何指向正确解决方案的指针都将受到欢迎!

谢谢, 亚历山德罗

I'm getting literally crazy trying to decrypt in JavaScript a string encrypted in PHP with the following code snippet:

function myencrypt($str) {
    $iv = '1234567890abcdef';
    $key = 'abcdef1234567890';

    $td = mcrypt_module_open('rijndael-128', '', 'cbc', $iv);
    mcrypt_generic_init($td, $key, $iv);
    $encrypted = mcrypt_generic($td, $str);

    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);

    return bin2hex($encrypted);
}

I've tried slowAES, gibberish-aes and some other available JS libraries, but always failed to correctly decrypt a single string.

I've also extensively searched in SO, but was unable to find a solution applicable to my situation.

Any pointer toward the right solution would be more than welcome!

Thanks,
Alessandro

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

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

发布评论

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

评论(1

任性一次 2024-12-21 00:36:07

您是否尝试过 crypto-js 库?抱歉,但我不确定 mcrypt_module_open('rijndael-128' 到底做了什么,但如果它只使用 CBC 它应该可以工作

have you tried the crypto-js library? Sorry but i'm not sure what mcrypt_module_open('rijndael-128' does exactly but if it just uses CBC it should work

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