The CodeIgniter 2.0.2 requires to set an encryption key in the config file i.e. $config['encryption_key']
, if you want to use Session class. Can it be any string? Any example of secure encryption_key?
Thanks.
Encrypting and decrypting data with the already configured library settings is simple. As simple as just passing the string to the encrypt() and/or decrypt() methods: $plain_text = 'This is a plain-text message! '; $ciphertext = $this->encryption->encrypt($plain_text); // Outputs: This is a plain-text message!
This key should be any random string but not a simple plain text and should be 32 characters in length (128 bits). Below we have created an example to show, how to encode and decode the data. To decode the code use: $this->encrypt->decode() // Decrypts an encoded string.
Encryption is the method by which information is converted into secret code that hides the information's true meaning. The science of encrypting and decrypting information is called cryptography. In computing, unencrypted data is also known as plaintext, and encrypted data is called ciphertext.
The key should be as random as possible and it must not be a regular text string, nor the output of a hashing function, etc.
To save your key to your application/config/config.php, open the file and set:
$config['encryption_key'] = 'yourKeyHere'
Random Key Generator
It's important for you to know that the encoded messages the encryption function generates will be approximately 2.6 times longer than the original message. For example, if you encrypt the string "my super secret data", which is 21 characters in length, you'll end up with an encoded string that is roughly 55 characters (we say "roughly" because the encoded string length increments in 64 bit clusters, so it's not exactly linear). Keep this information in mind when selecting your data storage mechanism. Cookies, for example, can only hold 4K of information.
In addition to the answer by Chumillas, I personally use this Random Key Generator for my CodeIgniter encryption strings. Quick and easy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With