Welcome Guest, Not a member yet? Register   Sign In
Encryption produces gibberish string
#1

$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;"
Reply
#2

(This post was last modified: 02-07-2021, 03:53 AM by craig.)

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/l...or-results


I think you have the base64_encode in the wrong place.
Reply
#3

(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/l...or-results


I think you have the base64_encode in the wrong place.



I figured it out, thanks. 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB