PHP通过URL发送加密数据 [英] PHP sending encrypted data via the URL
问题描述
我试图通过URL发送加密数据到另一个地方(使用的file_get_contents(anotherUrl.php?哈希= $ encryptedString)
,问题是,有时,加密包含一些特殊的字符,例如+,这导致解密失败。
I'm trying to send encrypted data over the url to another site (using file_get_contents("anotherUrl.php?hash=$encryptedString")
. The problem is, sometimes, the encryption contains some special characters, like +, and this causes the decryption to fail.
下面是我的加密/解密方法:
Here are my encryption / decryption methods:
public function encrypt($string, $key)
{
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
}
public function decrypt($encrypted, $key)
{
return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
}
下面是它包含一个 +
,和我猜测,这会导致解密失败的例子加密的字符串。
Here's an example encrypted string which contains a +
, and I'm guessing that this causes the decryption to fail.
oWCrVPaS + 5GbxcQFc0fulUk / zRAkDD60av4zlPiWskE =
任何想法,我应该怎么解决这个问题?我试着做 urlen code()
和 urlde code()
散列然而也似乎导致加密断裂。有没有办法来改变加密算法得到它只有返回URL安全字符?
Any ideas how I should solve this? I've tried to do urlencode()
and urldecode()
on the hash, however that also seems to cause the encryption to break. Is there a way to change the encryption algorithm to get it to only return url safe characters?
推荐答案
在这个线程看看:
从本质上讲,你的 DO 希望 urlen code()
发送字符串之前,但是你做的不可以希望 urlde code()
在另一端。
Essentially you DO want to urlencode()
before sending the string, however you do NOT want to urldecode()
at the other end.
这篇关于PHP通过URL发送加密数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!