CodeIgniter Forums
Codeigniter mcrypt encode and decode - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Codeigniter mcrypt encode and decode (/showthread.php?tid=64619)



Codeigniter mcrypt encode and decode - sasatozovic - 03-13-2016

Can anyone help me on how to set a few parameters in codeigniter and encode and decode an array? I was looking over a few hours on the Internet and didn't find any answer.

I'm looking for something like this, to take some array:

Code:
Array
(
   [product_key] => 5D6E-DR8R-ADDD-WQE5
   [name] => laptop
   [price] => 399.99
)


to encode with these parameters:

Code:
mcrypt_key='12som456ething99';
mcrypt_iv='fgdsd849848877ht';
mcrypt_mode='cbc';
mcrypt_cipher='rijndael-128';
 
and later to decode and print array.

Anyone?


RE: Codeigniter mcrypt encode and decode - skunkbad - 03-13-2016

All you need to do is serialize the array before you encode it, and then unserialize the array after you decode it. Look in the PHP manual for serialize and unserialize functions.


RE: Codeigniter mcrypt encode and decode - sasatozovic - 03-13-2016

How to set these parameters first?

I know for serialize. How to write all that in CI?


RE: Codeigniter mcrypt encode and decode - skunkbad - 03-13-2016

I don't see anything in the docs where you can set your own IV. I don't think it's possible using the CI3.0.X Encryption library. Maybe somebody (like Narf) can tell you a solution.