PHP通过URL发送加密数据 [英] PHP sending encrypted data via the URL

查看:197
本文介绍了PHP通过URL发送加密数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过URL将加密数据发送到另一个站点(使用 file_get_contents(anotherUrl.php?hash = $ encryptedString)。问题是,有时,加密包含一些特殊字符,如+,这会导致解密失败。



这是我的加密/解密方法:

  public function encrypt($ string,$ key)
{
返回base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256,md5($ key),$字符串,MCRYPT_MODE_CBC,md5(md5($ key))));
}

公共函数解密($ encrypted,$ key)
{
return rtrim mcrypt_decrypt(MCRYPT_RIJNDAEL_256,md5($ key),base64_decode($ encrypted),MCRYPT_MODE_CBC,md5(md5($ key))),\0);
}


$ code $ oBB b <任何想法应该如何解决? X-454545454545 CEEC X- 20045 X- 20045 X- 200 X- 20045 X- 200 X- 20045 X- 200 X- 200 200 X- 200 200 X- 200 200:加密破解有没有办法改变加密算法,让它只返回url的安全字符?

解决方案

看看这个线程:



传递base64编码的字符串在URL



本质上您 DO 想要 urlencode() before发送字符串,但是您在另一端想要 urldecode()


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=

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?

解决方案

Take a look at this thread:

Passing base64 encoded strings in URL

Essentially you DO want to urlencode() before sending the string, however you do NOT want to urldecode() at the other end.

这篇关于PHP通过URL发送加密数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆