CodeIgniter Forums
Encryption output - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Encryption output (/showthread.php?tid=77349)



Encryption output - falcon812311 - 08-20-2020

Hello guys!

I have problem with CI4 encryption and decryption...

The problem is from encryption method it is show strange output.
Sample Output:

http://prnt.sc/u2vmwi


My Setting in .env:

PHP Code:
encryption.key 'thisismykey' 
encryption.driver OpenSSL 


My code:

PHP Code:
$encrypter = \Config\Services::encrypter();
$plainText 'This is a plain-text message!';
$ciphertext $encrypter->encrypt($plainText);
echo 
$ciphertext

I hope someone can help me about the output from encryption.

Btw, CodeIgniter framework is awesome!


RE: Encryption output - paulbalandan - 08-20-2020

The output of encrypt is a binary string. So it will render on your screen strangely. You should encode it using either bin2hex or base64_encode before echoing.


RE: Encryption output - falcon812311 - 08-21-2020

(08-20-2020, 12:22 PM)paulbalandan Wrote: The output of encrypt is a binary string. So it will render on your screen strangely. You should encode it using either bin2hex or base64_encode before echoing.
Thank you, now I understand.