solution is to remove spaces of the output of xxd
in bash :
res=`xxd -p $exportedkey`
echo "${res//[[:space:]]/}"
in php :
$hex = hex2bin($result);
header("Content-Description: File Transfer");
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=hex.pfx");
header('Content-Length: '. strlen($hex));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
echo $hex;
exit();
hope it helps at least someone