authToken加密与urlencoding / urldecoding和.htaccess问题 [英] authToken encryption with urlencoding/urldecoding and .htaccess issue
问题描述
我有一个.htaccess启用,它遇到了这个url提到的javascript / php通信的问题。 http:// www。 tequilafish.com/2007/12/06/mod_rewrite-php-how-to-match-urlencoded-plus-sign/
根据建议该帖子,我不能urlencode两次,因为前端系统不在我的控制之下,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule ^(。+)$ index.php?uri = $ 1 [QSA,L]
。
class Crypt {
public static function encrypt($ data,$ secret){
$ iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
$ iv = mcrypt_create_iv($ iv_size,MCRYPT_RAND);
$ key = pack('H *',$ secret);
return base64_encode($ iv。mcrypt_encrypt(MCRYPT_RIJNDAEL_128,$ key,$ data,MCRYPT_MODE_CBC,$ iv));
}
public static function decrypt($ data,$ secret){
$ data = base64_decode($ data);
$ iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
$ iv = substr($ data,0,$ iv_size);
$ data = substr($ data,$ iv_size);
$ key = pack('H *',$ secret);
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128,$ key,$ data,MCRYPT_MODE_CBC,$ iv),chr(0));
}
}
if你想要发送数据在url,那么你必须使用urlencode,并在哪里你得到数据urldecode。使用urlencode删除所有空间和空格字符和urldecode,您将获得真实数据
示例:
$ abc = urlencode ($ abc);
然后发送在url
redirec:authToken加密与urlencoding / urldecoding和.htaccess问题 $ abc
我得到它的东西:)
how to generate tokens when you have encryption with url encoding/urldecoding and .htaccess file involved.
I've a .htaccess enabled as well and it ran into a problem of javascript/php communication mentioned on this url. http://www.tequilafish.com/2007/12/06/mod_rewrite-php-how-to-match-urlencoded-plus-sign/
as per the suggestion by the post, I can't urlencode twice, as frontend system is not under my control,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]
.
class Crypt {
public static function encrypt($data, $secret) {
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$key = pack('H*', $secret);
return base64_encode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv));
}
public static function decrypt($data, $secret) {
$data = base64_decode($data);
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = substr($data, 0, $iv_size);
$data = substr($data, $iv_size);
$key = pack('H*', $secret);
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv), chr(0));
}
}
if You want send data in url then you must use urlencode and where ever you get data urldecode. With urlencode remove all space and spacial character and urldecode you get real data
Example :
$abc = urlencode($abc);
then send it in url
redirec : authToken encryption with urlencoding/urldecoding and .htaccess issue$abc
I thing you get it :)
这篇关于authToken加密与urlencoding / urldecoding和.htaccess问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!