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