Search code examples
phpapachemod-rewriteencryptionmcrypt

Encrypting a value with Mcrypt is using directory separator


I have a something that I want to encrypt and pass it via get in the URL, the value that I want to encrypt is something like '019230132_15/10/2012'(a number with a underline followed by a date in brazilian format), when I encrypt this value I get something like 'cMZns2q7U2vgD9t+zufUeKextc/WyuFB4WyVMQ=', but passing this via GET on the url is giving me problems cause the browser think that the '/' in the middle of the value is a directory separator, my encription algorithm is something like:

base64_encode(
    mcrypt_encrypt(
        MCRYPT_RIJNDAEL_256,
        md5(self::ENCRYPT_SALT),
        $value,
        MCRYPT_MODE_CBC,
        md5(md5(self::ENCRYPT_SALT))
    )
);

I don't even wanna know why this is happening, I just want some way that I can encrypt and decrypt a value, it doesn't have to be the seccurest way that has ever existed, because the information that i am giving does not worth the trouble of hacking it.

EDIT1:Using the PHP function urlencode is not working, I get a error 404 because the url_encode transforms '/' into '%2F', I think it is worth mention that I use mod_rewrite on my Apache

EDIT2: Managed to make urlencode work using it twice like urlencode(urlencode($value)), and decoding twice as well to get the original value


Solution

  • If you are creating the value in PHP (ie, passing the link from PHP to the browser in something like an a tag), use PHP's urlencode first.

    However, if you are using JavaScript, use javascript's escape functions, particularly encodeURIComponent