Encryption Key in CodeIgniter

CodeIgniter 2.0.2 requires you to set the encryption key in the configuration file, i.e. $config['encryption_key'] if you want to use the Session class. Could this be any line? Any example of secure key_ encryption?

Thanks.

+8
codeigniter
source share
8 answers

The key should be as random as possible and should not be a regular text string or the output of a hash function, etc.

To save your key in your application /config/config.php , open the file and install:

 $config['encryption_key'] = 'yourKeyHere' 

Random key generator

It is important for you to know that the encoded messages generated by the encryption function will be approximately 2.6 times longer than the original message. For example, if you encrypt the string “my super secret data” with a length of 21 characters, you will get an encoded string with a length of approximately 55 characters (we say “approximately” because the length of the encoded string is increased by 64). bit clusters, so it’s not quite linear). Consider this information when choosing a data storage engine. For example, cookies may contain only 4 KB of information.

+24
source share

In addition to Chumillas answer, I personally use this Random Key Generator for my CodeIgniter encryption strings. Fast and easy.

+17
source share

Codeigniter 3.1.0 YOU SHOULD NOT USE REGULAR TEXT FOR 'encryption_key'

"The key should be as random as possible, and it should not be a regular text string or the output of a hash function, etc. To create the correct key, you must use the create_key () method of the encryption libraries"

 $this->load->library('encryption'); $key = $this->encryption->create_key(16); // Get a hex-encoded representation of the key: $key = bin2hex($this->encryption->create_key(16)); // Put the same value in your config with hex2bin(), // so that it is still passed as binary to the library: $config['encryption_key'] = hex2bin(<your hex-encoded key>); 

Source: https://codeigniter.com/userguide3/libraries/encryption.html#setting-your-encryption-key

+7
source share

Just go to the / config application

open config.php file

learn the word

 $config['encryption_key'] = ''; 

replace it with

 $config['encryption_key'] = 'your_encryption_key_here'; 
+2
source share

The encryption key can be any string, but to make it strong (for example, a good password), it is recommended that you select one that contains random alphanumeric characters. Also switch uppercase and lowercase letters.

To make this process simple, I created a convenient online solution that generates a random 32-digit alphanumeric encryption key for you. It can be used in any project for CodeIgniter, Laravel or where you need it.

encryption key generator

+1
source share

To save your key in the application /config/config.php , open the file and install:

on line 227 $config['encryption_key'] = "YOUR KEY";

0
source share

I am using the following code in my application. It takes 128 bytes of random data (converts to a hexadecimal string) and takes two characters at a time, converting them to decimal numbers and checking that they are in the valid range (alphanumeric, with characters, no spaces or characters that won't play well with your editor or configuration file - aka no ')

32 characters is 128 bits, so it works well with block ciphers.

 function random_key_string() { $source = bin2hex(openssl_random_pseudo_bytes(128)); $string = ''; $c = 0; while(strlen($string) < 32) { $dec = gmp_strval(gmp_init(substr($source, $c*2, 2), 16),10); if($dec > 33 && $dec < 127 && $dec !== 39) $string.=chr($dec); $c++; } return $string; } 
0
source share

Enter this in your terminal:

 php -r 'echo bin2hex(random_bytes(16)), "\n";' 

It will print a line where you update your config.php

0
source share

All Articles