e4rthdog
e4rthdog

Reputation: 5223

Codeigniter encode / decode different result for same string. Normal?

In my custom config i have a line like:

$config['encryption_key_posts'] ='vfy9SbKO!drtzwHkOvD46hGFedzaw3$l';

In a custom library i have:

class MyEncryption {

public $_CI;
public function __construct() {
    $this->_CI = & get_instance();
    $this->_CI->encrypt->set_cipher(MCRYPT_BLOWFISH);
    $this->_CI->encrypt->set_mode(MCRYPT_MODE_CBC);
}
function encode($str, $key) {
    return $this->_CI->encrypt->encode($str, $key);
}
function decode($str, $key) {
    return $this->_CI->encrypt->decode($str, $key);
    }
}

I am using it like this:

encode($_POST['post_title'],config_item('encryption_key_posts'))

and

decode($this->data['post']->post_title,config_item('encryption_key_posts'))

I am testing it with the same post_title = 'TEST' and i am always getting different results like:

Gk16w123clh3RZdYbGZc8g==
L64cWTVSaxWf8xGVVCRbyQ==
Ox2H4xAizS9lsKEQHzxRgg==

Is this normal? will i have any kind of issues if i move to a different server in the future?

Upvotes: 1

Views: 1805

Answers (1)

ivanargulo
ivanargulo

Reputation: 324

Well, I'll tell you from my personal experience that it's common when encoding with CodeIgniter (I've used it thousands of times for different purposes), although I don't know exactly why. I've tested it massively with lots of strings and you can rely safely on it.

It works perfect in different servers as long as you keep the same secret key and the same character encoding. I you move to a different server in the future the decryption will work fine.

Upvotes: 1

Related Questions