パスワードの暗号化に Yii CSecurityManager を使用しています。
$this->securityManager->encrypt('TEST', '1');
*TEST は暗号化する文字列で、1 はキーです。
しかし、復号化する前にテストすると、値が変化し続けることがわかりました。
for ($index = 0; $index < 10; $index++) {
$EncPassword = $this->securityManager->encrypt('TEST', '1');
echo $EncPassword;
}
私はアプリケーションの別の部分でこの値に依存しています...暗号化パスワードを掘り下げたところ、実際にはランダムであることがわかりました:
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;
}
私の質問は、キーに基づいて暗号化し、毎回同じ値を取得するにはどうすればよいですか?
ありがとう、ダニー