codeigniter encryption / decryption function returns empty string

the encrypt library requires the mcrypt extension.
codeigniter encrypt decrypt url
codeigniter encrypt url segment
this->encrypt->encode codeigniter
how to decrypt the md5 encrypted password in codeigniter
custom encryption and decryption in php
codeigniter 4 encryption
encrypt id in codeigniter

I am trying to login using codeigniter, but not able to do so. Then i tried to copy password from DB and pass it to dycription->decode() function, and it's returning empty string.

Here is the code


output was: string(0) ""

And this code also returning empty strings

$decoded_password = $this->encryption->decode($encoded_password); 
$decoded_username = $this->encryption->decode($encoded_username);

What i am doing wrong here?

UPDATE: i tried encrypting a string and PRINT IT then decrypt and PRINT, After encryption it returns NULL/Empty and after decryption it returns NULL/Empty (Obvious). Code is below

$encval = $this->encryption->encode('codeigniter');
echo $encval.'  --  IT WAS --'.'codeigniter';
echo "<br>---------------------------------------------------<br>";
echo $this->encryption->decode($encval);

OUTPUT: ^Nothing

Look, there are 2 ways to use encryption in CI and both should not be used for password(use hashing). First find out which one was used to encrypt the password and then stored in DB.Also, its possible some kind of KEY may have been used while encrypting the password check this too.

Below are the 2 encryption libs available in CI.

1.Encrypt class :

2.Encryption Lib:

decrypt data encrypted by CI 2.4 with CI 3.1, upgrading my application from CI 2.4 to CI 3.1, including changing Encrypt lib to Encryption, I found all decoded data returned empty strings. Your encryption key must be as long as the encryption algorithm in use allows. For AES-256, that’s 256 bits or 32 bytes (characters) long. 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 create a proper key, you can use the Encryption library’s createKey() method.

I had come across this problem, too.. My problem arised from database column varchar lenght limitation.. So, cipher text stored with missing part.. I changed column lenght from 50 to 250 then default option decode and encode work correctly

Encryption Library — CodeIgniter 3.1.11 documentation, Message Length; Configuring the library; Encrypting and decrypting data random as possible and it must not be a regular text string, nor the output of a hashing function, etc. you should always check the return value of decrypt() in production code. $hmac_key = $this->encryption->hkdf( $key, 'sha512', NULL, NULL,� But before doing all these process one must require to set up the encryption key. This Key is nothing but an information that controls the cryptographic process and allow encrypted string to get decrypted. This key should be any random string but not a simple plain text and should be 32 characters in length (128 bits).

I have resolved this issue by using Encryption library of Codeigniter, currently used library in my application was a little modified so it broke. now


This is working perfectly. I had to replace all encodes / decodes with encrypt / decrypt.

Thanks for your time guyz

Encryption Service — CodeIgniter 4.0.4 documentation, The Encryption Service provides two-way symmetric (secret key) data encryption. encrypting and decrypting data is simple - pass the appropriate string to encrypt() and it must not be a regular text string, nor the output of a hashing function, etc. Returns: CodeIgniter\Encryption\EncrypterInterface instance. Return type:. An encryption key is a piece of information that controls the cryptographic process and permits a plain-text string to be encrypted, and afterwards - decrypted. It is the secret “ingredient” in the whole process that allows you to be the only one who is able to decrypt data that you’ve decided to hide from the eyes of the public.

Proposal: encrypt->decode should verify integrity � Issue #2789 � bcit , If codeigniter wants to continue to offer encrypt/decrypt functionality, IMO, The encryption function should generate a random IV itself and use that. if it returns false there, then you are encrypting with the empty string key. 1 codeigniter encryption / decryption function returns empty string Mar 16 '19. 0 Error:Cause: buildToolsVersion is not specified Sep 26 '16. View all questions and

php: Codeigniter encryption library decrypt function always returns , Codeigniter encryption library decrypt function always returns empyt encrypt a string but I can't decrypt it, it always gives me empty string. The Encrypt Class provides two-way data encryption. It encrypted using the Mcrypt PHP extension, which is required for the Encrypt Class to run. A key is a piece of information that controls the cryptographic process and permits an encrypted string to be decoded. In fact, the key you chose will

Encryption and Decryption In CodeIgniter, One can perform the encryption in CodeIgniter with the help of encryption library. $this->encrypt->encode() // Performs the data encryption and returns it as a string function index() { $this->load->view('show_form'); } // Encode message public function NULL) { echo form_fieldset('Decrypted Message',� Easy Encryption A very simple yet powerful standalone C++ module (API) to obfuscate/deobfuscate strings based on B64 and Vigenere ciper (symmetric cipher). DISCLAIMER: This encryption is NOT secure and can be used as a "cheap way" to obfuscate some messages in a communication channel.

  • I would not use codeigniter encryption for password use
  • That is okay, but i have got an already built system that is using CI encryption.
  • @NomanAli wolfgang1983 is correct, you should not store your passwords in such a way that they can be decrypted. The function he suggests is the correct approach.
  • Following, Please Check $password = $this->input->post('password'); // that's what the user enters on the registration form $encrypted_password = $this->encryption->encode($password); // our encrypted password
  • So Encryption is used.
  • Try, $plain_text = 'This is a plain-text message!'; $ciphertext = $this->encryption->encrypt($plain_text); // Outputs: This is a plain-text message! echo $this->encryption->decrypt($ciphertext);
  • have you include encryption library in your controller?
  • add this to you function/class construct : $this->load->library('encryption');