0

A simple case , what's the suitable output for hexdump in bash (what needed options) to make it proper to be an input for hex2bin function in php !
P.S : I'm using it for streaming a certificate (made by OpenSSL command) via web service .
I've updated PHP to 5.4.0 & I'm using CentOS 6

SafeY
  • 287
  • 2
  • 6
  • 18

2 Answers2

0

hexdump -e '1/1 "%02x"' does the trick.

P.S. To avoid extra dependencies on hexdump binary you might want to consider using php for that and to write a short loop reading from stdin and writing out via bin2hex().

ash108
  • 1,763
  • 1
  • 17
  • 21
  • output of this command didn't go with hex2bin . no error or warning and no output either . I'm forced to make this sequence in calling to separate bash code which deals with files on the server from web service from PHP interface which just deal with WS response . – SafeY Jun 22 '13 at 13:20
0

solution is to remove spaces of the output of bash 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 this helps others who have same problem .

SafeY
  • 287
  • 2
  • 6
  • 18