authToken encryption with urlencoding/urldecoding and .htaccess issue

白昼怎懂夜的黑 提交于 2019-12-13 06:05:30

问题


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));
   }
  }

回答1:


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 :)



来源:https://stackoverflow.com/questions/21049220/authtoken-encryption-with-urlencoding-urldecoding-and-htaccess-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!