将证书流式传输到 stdout 以在 php 中下载它

将证书流式传输到 stdout 以在 php 中下载它

相关问题:

如何转换(完整)p12/pfx 证书以在 Web 服务中接收它并将其重定向到 PJP 页面,我将其下载到浏览器。我用过xxdhexdumpod

但无法优化这些命令的输出,使其成为 PHP 中 hex2bin 函数的适当输入,以获取二进制文件以下载证书。

答案1

解决方案是删除 bash 中 bash 输出的空格:

res=`xxd -p $exportedkey`
echo "${res//[[:space:]]/}"

在 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();

相关内容