'Encyption with blowfish without plus sign
I want to pass an encrypted string as url parameter, below is my php script
$passphrase = "testte@t";
$cipher = "blowfish";
$id = "20220228-12";
$enc_str = openssl_encrypt($id, $cipher, $passphrase);
$url = "https://example.com/?p={$enc_str}";
finally the $url is encrypted as
https://example.com/?p=BNrdu+t/YVgefLcrCxmuug==
if I get the value of parameter using $_REQUEST['p'], the encryped string will be returned as BNrdu t/YVgefLcrCxmuug== which lost the char sign '+', how can I avoid the encrypted string with the char '+'? Should I change another cipher? Which one is the best?
Solution 1:[1]
$param = "BNrdu+t/YVgefLcrCxmuug==";
$encoded = urlencode($param);
echo "https://example.com/?p=$encoded";
will output https://example.com/?p=BNrdu%2Bt%2FYVgefLcrCxmuug%3D%3D.
Then when receiving data:
$param = urldecode($_GET["p"] ?? ""); // BNrdu+t/YVgefLcrCxmuug==
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Code Spirit |
