转换证书时 PowerShell 中的 Openssl 错误
Openssl errors in PowerShell when converting certificates
我目前正在将 CER 转换为 PEM。
我正在构建一个脚本,使用 Openssl 将多个证书转换为不同的格式。我正在 运行ning PowerShell 7 和 Openssl 1.1.1e。当我 运行 我的脚本时,我遇到了一些 Openssl 错误,但是它似乎仍然转换了证书,因为之后我仍然得到一个 .pem 文件。以下是错误:
Can't open Folder\Path for reading, Permission denied
17956:error:02001005:system library:fopen:Input/output error:..\crypto\bio\bss_file.c:69:fopen('C:\Users\localadmin\Desktop\PowerShell\Testing Environment\Folder\Path','r')
17956:error:2006D002:BIO routines:BIO_new_file:system lib:..\crypto\bio\bss_file.c:78:
unable to load certificate
Can't open Folder\Path for reading, Permission denied
19560:error:02001005:system library:fopen:Input/output error:..\crypto\bio\bss_file.c:69:fopen('C:\Users\localadmin\Desktop\PowerShell\Testing Environment\Folder\Path','r')
19560:error:2006D002:BIO routines:BIO_new_file:system lib:..\crypto\bio\bss_file.c:78:
unable to load certificate
unable to load certificate
17960:error:0909006C:PEM routines:get_name:no start line:..\crypto\pem\pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
unable to load certificate
16568:error:0909006C:PEM routines:get_name:no start line:..\crypto\pem\pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
unable to load certificate
21500:error:0909006C:PEM routines:get_name:no start line:..\crypto\pem\pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
unable to load certificate
15500:error:0909006C:PEM routines:get_name:no start line:..\crypto\pem\pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
我在使用 Openssl 制作 CSR 或私钥时没有遇到任何错误。以下是我用于转换的代码:
if($CertType -eq "PEM") {
Get-ChildItem $ScriptPath$Kit -Recurse -Force | ForEach-Object {
$OutFile = $_.FullName.ToString().Replace(".cer",".pem")
openssl x509 -in $_.FullName -outform PEM -out "$Outfile"}
}
默认的 openssl x509 命令格式是 pem,因此您的命令行正在从 pem 转换为 pem。
所以错误是 openssl 不理解文件格式,因为它需要 pem 格式的文件。
我假设您想将 DER 格式转换为 PEM 格式。
所以你想要做的是:
openssl x509 -in {infilename} -inform der -out {outfilename}
这将期望 DER 格式的文件作为 PEM 格式的文件输入和输出。
或者您可以明确指定双方,例如:
openssl x509 -in {infilename} -inform der -out {outfilename} -outform pem
来自手册:
-inform DER|PEM
This specifies the input format normally the command will expect an
X509 certificate but this can change if other options such as -req are
present. The DER format is the DER encoding of the certificate and PEM
is the base64 encoding of the DER encoding with header and footer
lines added. The default format is PEM.
-outform DER|PEM
This specifies the output format, the options have the same meaning
and default as the -inform option.
能够弄清楚。在我将 CER 文件转换为 PEM 的代码中,当递归遍历我的文件夹时,我添加了一行以仅包含 CER 文件而不包含其中的密钥文件。下面是编辑后的代码。
if($CertType -eq "PEM") {
Get-ChildItem $ScriptPath$Kit -Recurse -include "*.cer" | ForEach-Object {
$OutFile = $_.FullName.ToString().Replace(".cer",".pem")
openssl x509 -in $_.FullName -outform PEM -out "$Outfile"}
}
我目前正在将 CER 转换为 PEM。
我正在构建一个脚本,使用 Openssl 将多个证书转换为不同的格式。我正在 运行ning PowerShell 7 和 Openssl 1.1.1e。当我 运行 我的脚本时,我遇到了一些 Openssl 错误,但是它似乎仍然转换了证书,因为之后我仍然得到一个 .pem 文件。以下是错误:
Can't open Folder\Path for reading, Permission denied
17956:error:02001005:system library:fopen:Input/output error:..\crypto\bio\bss_file.c:69:fopen('C:\Users\localadmin\Desktop\PowerShell\Testing Environment\Folder\Path','r')
17956:error:2006D002:BIO routines:BIO_new_file:system lib:..\crypto\bio\bss_file.c:78:
unable to load certificate
Can't open Folder\Path for reading, Permission denied
19560:error:02001005:system library:fopen:Input/output error:..\crypto\bio\bss_file.c:69:fopen('C:\Users\localadmin\Desktop\PowerShell\Testing Environment\Folder\Path','r')
19560:error:2006D002:BIO routines:BIO_new_file:system lib:..\crypto\bio\bss_file.c:78:
unable to load certificate
unable to load certificate
17960:error:0909006C:PEM routines:get_name:no start line:..\crypto\pem\pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
unable to load certificate
16568:error:0909006C:PEM routines:get_name:no start line:..\crypto\pem\pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
unable to load certificate
21500:error:0909006C:PEM routines:get_name:no start line:..\crypto\pem\pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
unable to load certificate
15500:error:0909006C:PEM routines:get_name:no start line:..\crypto\pem\pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
我在使用 Openssl 制作 CSR 或私钥时没有遇到任何错误。以下是我用于转换的代码:
if($CertType -eq "PEM") {
Get-ChildItem $ScriptPath$Kit -Recurse -Force | ForEach-Object {
$OutFile = $_.FullName.ToString().Replace(".cer",".pem")
openssl x509 -in $_.FullName -outform PEM -out "$Outfile"}
}
默认的 openssl x509 命令格式是 pem,因此您的命令行正在从 pem 转换为 pem。 所以错误是 openssl 不理解文件格式,因为它需要 pem 格式的文件。
我假设您想将 DER 格式转换为 PEM 格式。 所以你想要做的是:
openssl x509 -in {infilename} -inform der -out {outfilename}
这将期望 DER 格式的文件作为 PEM 格式的文件输入和输出。
或者您可以明确指定双方,例如:
openssl x509 -in {infilename} -inform der -out {outfilename} -outform pem
来自手册:
-inform DER|PEM
This specifies the input format normally the command will expect an X509 certificate but this can change if other options such as -req are present. The DER format is the DER encoding of the certificate and PEM is the base64 encoding of the DER encoding with header and footer lines added. The default format is PEM.
-outform DER|PEM
This specifies the output format, the options have the same meaning and default as the -inform option.
能够弄清楚。在我将 CER 文件转换为 PEM 的代码中,当递归遍历我的文件夹时,我添加了一行以仅包含 CER 文件而不包含其中的密钥文件。下面是编辑后的代码。
if($CertType -eq "PEM") {
Get-ChildItem $ScriptPath$Kit -Recurse -include "*.cer" | ForEach-Object {
$OutFile = $_.FullName.ToString().Replace(".cer",".pem")
openssl x509 -in $_.FullName -outform PEM -out "$Outfile"}
}