I have an encrypt / decrypt code found on stackoverflow. It is this one:
public function decrypt_blowfish($data,$key){
try{
$iv = pack("H*" , substr($data,0,16));
$x = pack("H*" , substr($data,16));
$res = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $x , MCRYPT_MODE_CBC, $iv);
return $res;
}catch(Exception $ex){
echo $ex->getMessage();
}
}
function encrypt_blowfish($data,$key){
try{
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $data, MCRYPT_MODE_CBC, $iv);
return bin2hex($iv . $crypttext);
}catch(Exception $ex){
echo $ex->getMessage();
}
}
it works fine if i test it just with a php without values out of a database, but if i use it with values out of a database i get things like "Manuel��" instead of just "Manuel" - can you tell me what is my mistake?
mcrypt
is abandonware. There are many examples of proper encryption/decryption implementation in PHP on github. Consider wiping this code and replacing it with this one. – Mjh