CodeIgniter Forums
Encryption produces gibberish string - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Encryption produces gibberish string (/showthread.php?tid=78551)



Encryption produces gibberish string - dennisdup - 02-06-2021

$this->config    = new \Config\Encryption();
$this->encrypter = \Config\Services::encrypter($this->config); 
$ciphertext =  $this->encrypter->encrypt(base64_encode($text));


When I echo $ciphertext, I get some gibberish text(see below). Ideally, I am saving this value in the database. Is this normal?

�wD�yL��'T�Z��Oq�J��H1�b���~��x��q���a��A=�8���d�/�Ȍ�$� T����"��F�����Ѝ��5%�T;"


RE: Encryption produces gibberish string - craig - 02-07-2021

Quote:You’ll notice that the createKey() method outputs binary data, which is hard to deal with (i.e., a copy-paste may damage it), so you may use bin2hex(), or base64_encode to work with the key in a more friendly manner.

You might find the same technique useful for the results of encryption:
Code:
// Encrypt some text & make the results text
$encoded = base64_encode($encrypter->encrypt($plaintext));

https://www.codeigniter.com/user_guide/libraries/encryption.html#encoding-keys-or-results


I think you have the base64_encode in the wrong place.


RE: Encryption produces gibberish string - dennisdup - 02-07-2021

(02-07-2021, 03:53 AM)craig Wrote:
Quote:You’ll notice that the createKey() method outputs binary data, which is hard to deal with (i.e., a copy-paste may damage it), so you may use bin2hex(), or base64_encode to work with the key in a more friendly manner.

You might find the same technique useful for the results of encryption:
Code:
// Encrypt some text & make the results text
$encoded = base64_encode($encrypter->encrypt($plaintext));

https://www.codeigniter.com/user_guide/libraries/encryption.html#encoding-keys-or-results


I think you have the base64_encode in the wrong place.



I figured it out, thanks.