Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php openSLL Encryption - to prevent special characters

Tags:

I want to create and encryption for get variabile passed in url and for asynchronous call

for example:

$textToEncrypt = "Hello World";
$encryptionMethod = "AES-256-CBC";
$secretHash = "cVb67YtfAz328oOikl96vBn";
$iv = "adfrf54dmnlo09ax";
$encryptedText = openssl_encrypt($textToEncrypt,$encryptionMethod,$secretHash, 0, $iv);

result is: W2p0S2qlSierJnIcA/AM3g==

there are some special characters, == always at the end. I want to prevent this! How can I output only 0-9 and A-Z and a-z characters?

thanks

like image 364
Cristian Avatar asked Oct 18 '16 14:10

Cristian


1 Answers

I had the same issue. I wanted to remove the special characters. So, this is what I did. Convert the encrypted text into hex value using base64_encode($encryptedText). So, there will be no special characters. Then for the revert, use base64_decode before passing to openssl_decrypt.

like image 177
hafij Avatar answered Oct 05 '22 11:10

hafij