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

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

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?