Earlier I was storing data in Database without Encrypting. But Now i need to Encrypt both the existing data as well as newly inserted data.
So here What i did: For encryption of existing data I used AES_ENCRYPT() method ,
Update table
SET poster_id
= AES_ENCRYPT('poster','Mykey') ;
It is working fine and i am able to DECRYPT data using AES_DECRYPT() method .
In code i have done changes as :
$config['encryption_key'] = 'Mykey'; //in config.php page.
and encrypted value using
$encrypted_string = $this->encrypt->encode($poster_id);
This is also working fine as i am able to ENCRYPT NEW inserting data to database.
But when i am trying to DECRYPT all the data now by using AES_DECRYPT() function (both existing and newly inserted data ).I am getting correct value for old data and getting Null value for the newly inserted data . Please suggest on this or give any alternative solution.
Thank You.
AES_DECRYPT
returnsNULL
if it detects invalid data. It sounds like codeigniter generated a bad encryption – patrick3853$this->encrypt->encode()
is identical to mysql'sAES_ENCRYPT
? – zerkms