与URL编码/ urldecoding和.htaccess问题的authToken加密 [英] authToken encryption with urlencoding/urldecoding and .htaccess issue
问题描述
如何生成的令牌,当你有加密用URL编码/ urldecoding和参与.htaccess文件。
我有一个htaccess的启用,以及和它遇到了这个URL中的JavaScript / PHP通信的问题。的http://www.tequilafish.com/2007/12/06/mod_rewrite-php-how-to-match-urlen$c$cd-plus-sign/
根据建议的帖子,我不能urlen code两次,作为前端系统是不是我的控制之下,
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。+)$的index.php?URI = $ 1 [QSA,L]
类地穴{
公共静态函数加密($数据,$密码){
$ iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
$ IV = mcrypt_create_iv($ iv_size,MCRYPT_RAND);
$键=包('H *',$密码);
返回base64_en code($四mcrypt_encrypt(MCRYPT_RIJNDAEL_128,$关键,$数据,MCRYPT_MODE_CBC,$ IV));
}
公共静态函数解密($数据,$密码){
$数据= base64_de code($的数据);
$ iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
$ IV = SUBSTR($的数据,0,$ iv_size);
$数据= SUBSTR($数据,$ iv_size);
$键=包('H *',$密码);
返回修剪(mcrypt_decrypt(MCRYPT_RIJNDAEL_128,$键,$数据,MCRYPT_MODE_CBC,$ iv)中,字符(0));
}
}
如果你想在URL发送数据,则必须使用urlen code和在任何你得到的数据urlde code。随着urlen code删除所有空间和空间的性格和urlde code你得到真实的数据。
例如:
$ ABC = urlen code($ ABC);
那么它的URL发送
redirec:用URL编码/ urldecoding和.htaccess问题 $ ABC
的authToken加密我的事情,你得到它:)
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 :)
这篇关于与URL编码/ urldecoding和.htaccess问题的authToken加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!