I’m doing a encode() from the Encrypt class and each time it returns a different string for the same input string.
My application/config/encrypt.php:
return array(
'default' => array(
/**
* The following options must be set:
*
* string key secret passphrase
* integer mode encryption mode, one of MCRYPT_MODE_*
* integer cipher encryption cipher, one of the Mcrpyt cipher constants
*/
'cipher' => MCRYPT_RIJNDAEL_128,
'key' => 'df58e28f',
'mode' => MCRYPT_MODE_NOFB,
),
);
Use:
$str = Encrypt::instance()->encode('test');
$str has always a different value. Is that an error or it’s supposed to work that way? Why?
Also I must add that I can always decode() that value and get the test string each time.
UPDATE: Here is a sample output: 0vahDa/2Qu3XQWObkjwLPoL73g==
Thank you very much.
Actually this is intentional behaviour.
IMHO this way the encryption is more secure. Most pseudo hackers would think different encrypted values mean different actual values.
The important thing is that you always get the same value upon decryption.
You have to be careful with that: when you want to use the same encrypted string twice you should store it separately, because encrypting again would not produce the same thing.