Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter Encryption Key

Say I have this set up as my encryption key and I already have the encrypt library on autoload:

$config['encryption_key'] = 'bjA{<ATCs1w5?,8N(bJvgO3CW_<]t?@o';

How do I use it in an encrypt function?

function s()
{
    $something = $this->encrypt->encode('eoaighaeg',$key);
    echo $this->encrypt->decode($something, $key); 
}

^ Non working example to give you an idea.

like image 592
daryl Avatar asked Dec 01 '11 06:12

daryl


2 Answers

According to this documentation, http://codeigniter.com/nightly_user_guide/libraries/encryption.html

If you didn't supply any key parameter for $this->encrypt->encode() function, it automatically use config encryption key.

$this->encrypt->encode($msg);
like image 148
Manjula Avatar answered Sep 29 '22 01:09

Manjula


You don't. CI already does that, as you can read on the manual

If you want to pass a custom key, different from that one used in the config file, you need to specify it first:

$msg = 'Message';
$key = 'bjA{<ATCs1w5?,8N(bJv';

$encrypted_string = $this->encrypt->encode($msg, $key);

But that works only locally, otherwise you just use

$this->encrypt->encode($msg)

and CI applies the default one.

As with decoding it goes the same way, you don't specify the key if you use the default key, else pass your custom one as second parameter of $this->encrypt->decode()

like image 30
Damien Pirsy Avatar answered Sep 29 '22 03:09

Damien Pirsy