daryl
daryl

Reputation: 15197

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.

Upvotes: 5

Views: 9185

Answers (2)

Manjula
Manjula

Reputation: 5091

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);

Upvotes: 8

Damien Pirsy
Damien Pirsy

Reputation: 25425

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()

Upvotes: 4

Related Questions