json - 将文件保存为 .pem 从 powershell 5.1 编码为 utf8noBOM 并使用 openssl 读取它会引发错误
问题描述
我正在尝试使用 powershell 将 .pem 文件上传到 API,我们必须将其转换为 JSON 格式然后发布。好吧,使用下面的代码片段可以正常工作
$t = Get-Content -Delimiter "`n" -Path 'xxxxxx.pem'
$a = [pscustomobject]@{"certificate" = "$($t)"
"description" = ""
"extension" = ".pem"}
$body = $a | convertto-json
$web = Invoke-WebRequest -Uri $url -ContentType "application/json" -Headers $headers -Body $body -Method POST
检索时,我正在使用以下代码段
$web = Invoke-WebRequest -Uri $url -ContentType "application/json" -Headers $headers
$temp = $web.Content | ConvertFrom-Json
$cert = $temp.data.certificate
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines("*****.pem", $cert, $Utf8NoBomEncoding)
然后我将使用上述代码段创建的文件传递给 openssl,如下
openssl.exe x509 -in "*****.pem" -checkend 129600
这给我带来了以下错误,
openssl.exe : unable to load certificate
At line:1 char:1
+ openssl.exe x509 -in "******.pem" -checkend 129600
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (unable to load certificate:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
14660:error:0909006C:PEM routines:get_name:no start line:crypto\pem\pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
我在这里很困惑,不知道我做错了什么。
因为这两个文件,原始 .pem 文件和从 PS 创建的文件都是 utf-8 编码的,并且在 notepad++ 中看不到任何 BOM 字符。
解决方案
推荐阅读
- apache-flink - Flink,使用 Hadoop 兼容性时的奇怪行为
- ios - Xcode 一直显示:-1: SWIFT_VERSION '5.0' is unsupported, 支持的版本是:3.0, 4.0, 4.2。任何解决方案?
- pyspark - 为什么胶水 pyspark ETL 作业无法将新列添加到镶木地板表中?
- jenkins - 无论如何要从 sshPublisher 获得一些返回码或异常?
- python - 如何从 Windows PC 创建 Pygame dmg 文件?
- javascript - 如何让 Socket 只发送给请求的客户端?
- html - 我可以为“网格列”设置动画吗?
- php - 管理下单逻辑
- python - TensorFlow Hub 模块可以在 TensorFlow 2.0 中使用吗?
- php - 在 Lumen 框架中清除缓存