dongyimeng3764 2013-06-20 07:05
浏览 75
已采纳

下载证书二进制数据时,结果是无效证书

I'm receiving binary data in php as certificate content and I want to download it to browser . I'm getting this message always when opening it with certificate viewer :

hex(19).pfx
Could not display 'hex(19).pfx'
Reason:   Unrecognized or unsupported data.

this binary data is correct , I put it in a file on the server immediately and it made a valid certificate .

I think the problem is in two where :

  • output of command

    exec('ssh root@192.168.0.137 "echo '.$bindata.' | xxd -p -r | tr -d \' \' "',$output);

while $bindata is coming from converting certificate pfx file after making it in bash with xxd -p

  • or it's in the header , there is a lost or addition :

    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($output[0]));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    echo $output[0];
    exit();
    

    what's the wrong ?

  • 写回答

1条回答 默认 最新

  • duan5731 2013-06-23 12:49
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?