我正在使用两个简单的函数来加密和解密密码。但是解密功能无法正常工作。这是我的输出:
加密:�\� ���#�%\��>�3,�o�Sd��c�
解密:test123
这是我的代码:
$size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
function encrypt($data)
{
$key = 'test';
$encrypted_data = mcrypt_cbc(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_ENCRYPT, $iv);
return $encrypted_data;
}
function decrypt($encryptedData)
{
$key = 'test';
$decrypt = mcrypt_cbc(MCRYPT_RIJNDAEL_256, $key, $encryptedData, MCRYPT_DECRYPT, $iv);
return $decrypt;
}
$password = encrypt($member[0]['PASSWORD']);
print('Encrypted: '.$password.'<br />');
$password = decrypt($password);
print('Decrypted: '.$password);