I am using two simple functions to encrypt and decrypt passwords. But the decrypt function is not working right. Here's my output:
Encrypted: �\� ���#�%\��>�3,�o�Sd��c�
Decrypted: test123
and here's my code:
$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);