首页 > 解决方案 > 无法使用 powershell 从章鱼库作为 X509Certificate2 对象访问 ssl 证书

问题描述

我正在尝试使用存储在 Octopus 库中的 pfx 创建一个 jwt 令牌。为此,我必须创建一个 X509Certificate2 对象,它将证书路径和密码作为输入。有人可以建议一种使用powershell的方法吗?

$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certpath,'password')

关于如何访问章鱼中的证书变量,我已经阅读了一些文档,但是如何使用它们来创建 X509Certificate2 的对象。 https://octopus.com/docs/deployment-process/variables/certificate-variables

标签: powershellsslssl-certificateoctopus-deployoctopus

解决方案


在浏览了 Microsoft 和 Octopus 文档后,我设法让它工作。Octopus 将证书作为 base64 编码字符串存储在名为 Cert.Pfx 的变量中,X509Certificate2 的构造函数将字节数组作为第一个参数。因此,第一步我只需要将 base64 编码的字符串转换为字节数组。

$certbytearray=[System.Convert]::FromBase64String($OctopusParameters["Cert.Pfx"])
$CertPassKey="password"
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certbytearray,$CertPassKey)

推荐阅读