为什么我的加密/解密对有时只返回原始明文?
我正在尝试加密格式 = LETTERS1234 的用户 ID 它的左侧可能包含一堆字母,并且最终会包含至少 1 个数字
我使用此代码创建了一个简单的测试网站:
<?php
$key = 'rsZOkGnJiQKf6zkZ';
$token = $_REQUEST['c'];
if(!$token){
$string = 'bgoogl1';
$enc = urlencode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key),
strtolower($string), MCRYPT_MODE_CBC,
md5(md5($key))));
header('Location: http://website.com/test.php?c='.$enc);
} else {
echo rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key),
urldecode($token), MCRYPT_MODE_CBC,
md5(md5($key))),"\0");
}
?>
结果大多数情况下都会为我提供任何 $string
$string,但对于这种情况和其他一些 $string
情况,它将失败并输出如下内容:
Ia$ÿ/ckY@Š«° =Û™¼îa¸ï³éð1œ_¹0Àã ¼/÷d‡¬ÐöT¨i“\M~¯D”¯“ÚÍ
我该如何解决这个问题?
PS 我也尝试过 rawurlencode 和 base64_encode 并解码。
I am trying to encrypt a user id of format = LETTERS1234
it could contain a bunch of letters in the left and will end up with at least 1 number
I made a simple test website using this code:
<?php
$key = 'rsZOkGnJiQKf6zkZ';
$token = $_REQUEST['c'];
if(!$token){
$string = 'bgoogl1';
$enc = urlencode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key),
strtolower($string), MCRYPT_MODE_CBC,
md5(md5($key))));
header('Location: http://website.com/test.php?c='.$enc);
} else {
echo rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key),
urldecode($token), MCRYPT_MODE_CBC,
md5(md5($key))),"\0");
}
?>
The result will give me most of the time the right output for any $string
, but for this case and some other $string
cases, it will fail and output something like this:
Ia$ÿ/ckY@Š«° =Û™¼îa¸ï³éð1œ_¹0Àã ¼/÷d‡¬ÐöT¨i“\M~¯D”¯“ÚÍ
How could I fix this?
P.S. I've tried with rawurlencode and base64_encode and decode as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,如果你想在HTTP请求中传递二进制数据,你将将其转换为十六进制:
然后,您可以将其打包回二进制文件:
注意:如果您对特定情况有问题,这将有助于知道是哪一个。
Generally speaking, if you want to pass binary data in a HTTP request, you will convert it to hexadecimal instead:
Then, you can pack it back to binary:
Note: If you have issues with a specific case, it would help to know which one.