Hi guys,
I just searched in the forum, but I didn't found the solution to my problem. The scenario is the following: I want to store in a file an encrypted database password and in run-time I want to read it from the file and decrypt it to connect to the DB.
The problem is that the output of the function returns strange characters, like these:
gSîBº[j—JëIž™Žº…Õ9˜Ö¯Ã*Óeg
I guess this is not correct 🙂
Here the code (founded in this forum):
<?php
function encryptData($value){
$key = "top secret key";
$text = $value;
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
return $crypttext;
}
$handle = fopen("/home/valeron/Desktop/crypt/pass.txt","a");
fwrite($handle,encryptData("valerio"));
fclose($handle);
?>
Could you help me to fix this issue, please?
Thank you very much!