Php 如何使用openssl解密此字符串

Php 如何使用openssl解密此字符串,php,encryption,openssl,Php,Encryption,Openssl,我在解密使用openssl加密的字符串时遇到一些问题。我没有更改加密代码的权限,但我有读取权限: 加密代码(无法修改) 解密页面上未返回解密文本已解决:我将decrypt.php更新为以下内容,它返回了解密文本 $ciphertext = $_GET['un']; $ciphertext = hex2bin($ciphertext); $ciphertext = base64_encode($ciphertext); $cipher = "aes-128-ecb"; $key = hex2bi

我在解密使用openssl加密的字符串时遇到一些问题。我没有更改加密代码的权限,但我有读取权限:

加密代码(无法修改)


解密页面上未返回解密文本已解决:我将decrypt.php更新为以下内容,它返回了解密文本

$ciphertext = $_GET['un'];
$ciphertext = hex2bin($ciphertext);
$ciphertext = base64_encode($ciphertext);

$cipher = "aes-128-ecb";
$key = hex2bin("24a5d2b96b9aee2fb515c94fb36da508");

$original_plaintext = openssl_decrypt($ciphertext, $cipher, $key);
echo "text= " . $original_plaintext;

对我有用。听起来WSOD掩盖了实际的错误。此外,ECB是一种非常糟糕的密码模式。看到这个wiki部分底部的图片:@Sammitch当你说它对你有用时,你的意思是它实际上解密了还是你看到了一个错误?我会看看我的错误报告是否需要一些调整,如果so@Sammitchre:ECB,我听到了,谢谢你的链接——这是一个很好的视觉方式,可以看到正在发生的事情。幸运的是,正在传递的数据并不敏感,这更像是我正在处理的一个表面情况啊,我认为这是密码的问题,我甚至没有看到编码。如果将
OPENSSL\u RAW\u DATA
作为加密/解密的第四个参数传递,则可以跳过base64编码/解码步骤。

$ciphertext = $_GET['un'];

$cipher = "aes-128-ecb";
$key = hex2bin("24a5d2b96b9aee2fb515c94fb36da508");

$original_plaintext = openssl_decrypt($ciphertext, $cipher, $key);
echo "text= " . $original_plaintext;
$ciphertext = $_GET['un'];
$ciphertext = hex2bin($ciphertext);
$ciphertext = base64_encode($ciphertext);

$cipher = "aes-128-ecb";
$key = hex2bin("24a5d2b96b9aee2fb515c94fb36da508");

$original_plaintext = openssl_decrypt($ciphertext, $cipher, $key);
echo "text= " . $original_plaintext;