encryption and decryption in codeigniter

Solutions on MaxInterview for encryption and decryption in codeigniter by the best coders in the world

showing results for - "encryption and decryption in codeigniter"
Élise
16 Feb 2020
1Note* : You might require to load driver if no driver is loaded 
2$this->encryption->initialize(
3  array(
4    'driver' => 'openssl',
5    'cipher' => 'aes-256',
6    'mode' => 'ctr'
7  )
8);
9
10STEP 1: Load a encryption library
11		
12$this->load->library('encryption');
13
14STEP 2: Create a encryption key for a config file application/config/config.php
15
16$this->encryption->create_key(16);
17############### OR #############
18bin2hex($this->encryption->create_key(16)); // For more user friendly cipher text
19
20Add this key inside the config file
21$config['encryption_key'] = hex2bin(<your hex-encoded key>);
22
23STEP 3: For encypt a plain text to cipher text
24
25$plain_text = 'This is a plain-text message!';
26$ciphertext = $this->encryption->encrypt($plain_text);
27
28STEP 4: Decrypt Cipher text to plain text 
29
30// Outputs: This is a plain-text message!
31echo $this->encryption->decrypt($ciphertext);