有没有一种方法可以将.der证书导出到.bin文件?

时间:2020-06-23 07:22:24

标签: powershell openssl x509certificate

我有一个x509 .der证书,需要将其连接到.bin软件包。问题是,如果我使用

pg_get_serial_sequence()

证书中的某些字符已更改。有没有办法使用openssl或其他方式将证书导出到.bin文件中?我正在使用Windows Powershell运行命令。

2 个答案:

答案 0 :(得分:2)

PowerShell中的重定向运算符(>>>)弄乱了您的二进制数据,因为它应用了基于$OutputEncoding的某些编码。在Get-ContentSet- / Add-Content之间进行配管不会修改您的数据。

因此您可以使用

Get-Content mycert.der -Raw | Add-Content package.bin -NoNewline

将证书作为二进制数据附加到二进制文件中。您需要-Raw,以便PowerShell可以保留任何CR / LF字节,还需要-NoNewline,以防止PowerShell在末尾添加自己的CR / LF。

答案 1 :(得分:1)

可能是因为Windows powershell cat将行尾\n替换为\r\n,您可以尝试复制文件吗

否则将转换证书

来自man opensslman x509

...
   Convert a certificate from PEM to DER format:

    openssl x509 -in cert.pem -inform PEM -out cert.der -outform DER

   Convert a certificate to a certificate request:

    openssl x509 -x509toreq -in cert.pem -out req.pem -signkey key.pem

   Convert a certificate request into a self signed certificate using extensions for a CA:

    openssl x509 -req -in careq.pem -extfile openssl.cnf -extensions v3_ca \
           -signkey key.pem -out cacert.pem
...