encrypt and decryption in codeigniter stack overflow

Note* : You might require to load driver if no driver is loaded 
$this->encryption->initialize(
  array(
    'driver' => 'openssl',
    'cipher' => 'aes-256',
    'mode' => 'ctr'
  )
);

STEP 1: Load a encryption library
		
$this->load->library('encryption');

STEP 2: Create a encryption key for a config file application/config/config.php

$this->encryption->create_key(16);
############### OR #############
bin2hex($this->encryption->create_key(16)); // For more user friendly cipher text

Add this key inside the config file
$config['encryption_key'] = hex2bin(<your hex-encoded key>);

STEP 3: For encypt a plain text to cipher text

$plain_text = 'This is a plain-text message!';
$ciphertext = $this->encryption->encrypt($plain_text);

STEP 4: Decrypt Cipher text to plain text 

// Outputs: This is a plain-text message!
echo $this->encryption->decrypt($ciphertext);

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source