I'm using Yii CSecurityManager for Password encryption:
$this->securityManager->encrypt('TEST', '1');
*the TEST is the string to encrypt and the 1 is the key.
but when i test before i decrypt i find that the value keeps changing.
for ($index = 0; $index < 10; $index++) {
$EncPassword = $this->securityManager->encrypt('TEST', '1');
echo $EncPassword;
}
i'm relying on this value in another part of my application...I dug into the encrypt password i see that it is in fact random:
public function encrypt($data,$key=null)
{
$module=$this->openCryptModule();
$key=$this->substr($key===null ? md5($this->getEncryptionKey()) : $key,0,mcrypt_enc_get_key_size($module));
srand();
$iv=mcrypt_create_iv(mcrypt_enc_get_iv_size($module), MCRYPT_RAND);
mcrypt_generic_init($module,$key,$iv);
$encrypted=$iv.mcrypt_generic($module,$data);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
return $encrypted;
}
so my question is how can i encrypt based on a key and get the same value each time?
thanks, Danny