Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从一个URL传递到另一个URL时出现Mcrypt问题_Php_Encryption_Obfuscation_Mcrypt - Fatal编程技术网

Php 从一个URL传递到另一个URL时出现Mcrypt问题

Php 从一个URL传递到另一个URL时出现Mcrypt问题,php,encryption,obfuscation,mcrypt,Php,Encryption,Obfuscation,Mcrypt,您好,我正在使用Mcrypt混淆通过邮件发送的一些值 当我在本地站点上加密并解密该值时,每次尝试都能正常工作,我会发送该值,但当我链接回我的站点并尝试在另一个页面上解密该值时,它有时只能正常工作 我有点卡住了,不知道为什么。我不太熟悉crypt函数 这是我用来加密的代码 这是我用来解密的代码 $password和$salt变量正在使用 pack("H*", $string); 在第一次尝试失败后,我开始对URL上的值使用urlencode和URDECODE,但仍然存在相同的问题 我做错了什么?

您好,我正在使用Mcrypt混淆通过邮件发送的一些值

当我在本地站点上加密并解密该值时,每次尝试都能正常工作,我会发送该值,但当我链接回我的站点并尝试在另一个页面上解密该值时,它有时只能正常工作

我有点卡住了,不知道为什么。我不太熟悉crypt函数

这是我用来加密的代码

这是我用来解密的代码

$password和$salt变量正在使用

pack("H*", $string);
在第一次尝试失败后,我开始对URL上的值使用urlencode和URDECODE,但仍然存在相同的问题

我做错了什么?我真的被困在这里了


谢谢

您的编码字符串将被发送加号,url上的加号将被解释为空格,您可以对url进行编码或使用str_replace更改字符串上加号的空格

这样


输出:随机化1234String+带+空格+空格

您已经在进行base64_编码,您不能对这些值进行URL编码,但它什么都不做。那些看似不常见的substr和trims是怎么回事?@FritsvanCampen在我的编辑中是带有commentstrim的原始代码,这里不用于删除空格。如果您提供第二个参数,它将修剪这些字符。但我想没关系。看看你能不能在邮件中找到一些弄乱URL的东西。没什么,我在没有邮件的情况下更改了测试,只是将值发送到另一个页面,我传递的加密字符串两边相等,但解密功能有时不起作用。是否有可能,无论您是否发送电子邮件,加密/解密功能有时都不起作用?如果是这样的话,我猜问题出在那些时髦的装饰中。
function decrypt($encrypted, $password, $salt='!kQm*fF3pXe1Kbm%9') {
 // Build a 256-bit $key which is a SHA256 hash of $salt and $password.
 $key = hash('SHA256', $salt . $password, true);
 // Retrieve $iv which is the first 22 characters plus ==, base64_decoded.
 $iv = base64_decode(substr($encrypted, 0, 22) . '==');
 // Remove $iv from $encrypted.
 $encrypted = substr($encrypted, 22);
 // Decrypt the data.  rtrim won't corrupt the data because the last 32 characters are the md5 hash; thus any \0 character has to be padding.
 $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($encrypted), MCRYPT_MODE_CBC, $iv), "\0\4");
 // Retrieve $hash which is the last 32 characters of $decrypted.
 $hash = substr($decrypted, -32);
 // Remove the last 32 characters from $decrypted.
 $decrypted = substr($decrypted, 0, -32);
 // Integrity check.  If this fails, either the data is corrupted, or the password/salt was incorrect.
 if (md5($decrypted) != $hash) return false;
 // Yay!
 return $decrypted;
 }
pack("H*", $string);
$encrypted_string= "random1234string with blank space";
$empty = array(" ");
$plus   = array("+");

$new_encrypted_string = str_replace($empty, $plus, $encrypted_string);