当前位置: 首页 > 知识库问答 >
问题:

如何使用openssl解密该字符串

上官霄
2023-03-14

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

加密代码(无法修改)

<?php 
$key = hex2bin("24a5d2b96b9aee2fb515c94fb36da508");
$encryptTxt = openssl_encrypt(
    "txt to encrypt",
    'AES-128-ECB',
    $key
);
?>

<a href="decrypt.php?un=<?php echo bin2hex(base64_decode($encryptTxt)) ?>">link</a>

$ciphertext = $_GET['un'];

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

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

共有1个答案

邹胜泫
2023-03-14

已解决:我将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;
 类似资料: