微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将 Base-64 pfx 转换为可用的 pkcs#12

如何解决将 Base-64 pfx 转换为可用的 pkcs#12

我已从 API 导出了基本 64 位编码的证书,现在需要将其转换为 pkcs12 格式以上传到 Azure。下面的 PowerShell 脚本完美地完成了这项工作,但我无法将其转换为 OpenSSL。

$base64value = Get-Content -Path $base64FilePath
$byteArray = [System.Convert]::FromBase64String($base64value)
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($byteArray,$certPw,[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
# Export the certificate as a PFX file
$bytesPfx = $cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pfx,$certPw)
[System.IO.File]::WriteallBytes($pkcs12FilePath,$bytesPfx)

我尝试了以下 2 个 OpenSSL 命令...

openssl base64 -d -a -in [base64.pfx] -out [converted.pfx]
openssl enc -base64 -d -in [base64.pfx] -out [converted.pfx]

...但是当我尝试使用证书时,它们都返回相同的错误

34359836736:error:0D07207B:asn1 编码例程:ASN1_get_object:header 太长:crypto/asn1/asn1_lib.c:101: pkcs12 中的错误

对这种转换的任何帮助将不胜感激。提前致谢!

解决方法

你可以试试下面的

从 base64 openssl 二进制格式转换 pfx

openssl enc -base64 -d -in base64.pfx -out converted.pfx

然后将其转换为 pkcs12 :

openssl pkcs12 -in converted.pfx -out bundle.pem -clcerts -nodes

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。