php - 如何使用 openssl 解密此字符串
问题描述
我在解密使用 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>
这是我尝试解密的方式:
解密.php
$ciphertext = $_GET['un'];
$cipher = "aes-128-ecb";
$key = hex2bin("24a5d2b96b9aee2fb515c94fb36da508");
$original_plaintext = openssl_decrypt($ciphertext, $cipher, $key);
echo "text= " . $original_plaintext;
解密页面上不返回解密后的文本
解决方案
已解决:我将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;
推荐阅读
- css - flex中不需要的内容拉伸
- javascript - 获取 API 未获取完整的 HTML 页面
- javascript - 当服务器上的表单数据经过验证并在 POST 内部被证明有效时,console.log() 不起作用并且 Nodemailer 不发送电子邮件
- corda - 在 Corda 中,运行 deployNodes 时出现 NoClassDefFoundError: SimpleFieldAccess 错误
- c++ - 为什么导入表中没有 memcpy?
- r - R Shiny - 以编程方式在闪亮材料中生成复选框
- html - HTML & CSS 导航栏间距
- jquery - 在 KeyPress 上隐藏/显示 DIV 不工作 jQuery
- angularjs - 如何将 ng-model 从指令传递到模板
- sql - 如何在选择上增加数字