A
Anonymous
Guest
Hello All,
Ive been having an issue and would be greatful if I can get some help to my problem. I need to pass a primary key in the URL. I would like to encrypt it for security.
I get the following outputs after calling my encrypt() and decrypt() methods (please see below for my code):
$result = encrypt("27");
value printed to screen: z0Da0HE7BfClV0q6hoKEt%2BkYs6CJxZkwCC7zd8%2BmIWU%3D
Value passed in url: z0Da0HE7BfClV0q6hoKEt+kYs6CJxZkwCC7zd8+mIWU=
I cannot understand why the values above are different. The same variable is printed and passed in the url.
encrypt($result);
value printed to screen: z0Da0HE7BfClV0q6hoKEt kYs6CJxZkwCC7zd8 mIWU=
The + is replaces with a space. I have tried to user str_replace after decrypting but it still prints the above.
Your help will be greatly appreciated.
Thanks,
Imran
Ive been having an issue and would be greatful if I can get some help to my problem. I need to pass a primary key in the URL. I would like to encrypt it for security.
I get the following outputs after calling my encrypt() and decrypt() methods (please see below for my code):
$result = encrypt("27");
value printed to screen: z0Da0HE7BfClV0q6hoKEt%2BkYs6CJxZkwCC7zd8%2BmIWU%3D
Value passed in url: z0Da0HE7BfClV0q6hoKEt+kYs6CJxZkwCC7zd8+mIWU=
I cannot understand why the values above are different. The same variable is printed and passed in the url.
encrypt($result);
value printed to screen: z0Da0HE7BfClV0q6hoKEt kYs6CJxZkwCC7zd8 mIWU=
The + is replaces with a space. I have tried to user str_replace after decrypting but it still prints the above.
Your help will be greatly appreciated.
Thanks,
Imran
Code:
function encrypt($input) {
$encrypted_result = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->securekey, $input, MCRYPT_MODE_ECB, $this->iv));
$encrypted_result = urlencode($encrypted_result);
return $encrypted_result;
}
function decrypt($input) {
$decrypted_result = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->securekey, base64_decode($input), MCRYPT_MODE_ECB, $this->iv));
$decrypted_result = str_replace(' ', '+', $decrypted_result );
return $decrypted_result;
}