【问题标题】:Unable to access ssl certificate from octopus library as X509Certificate2 object using powershell无法使用 powershell 从章鱼库作为 X509Certificate2 对象访问 ssl 证书
【发布时间】:2019-03-29 17:47:55
【问题描述】:
【问题讨论】:
标签:
powershell
ssl
ssl-certificate
octopus-deploy
octopus
【解决方案1】:
在浏览了 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)
【解决方案2】:
@Biplab 感谢您发布您的解决方案;它为我节省了很多头痛!我在没有密码的情况下遇到了稍微不同的情况,我发现当我尝试在没有密码的情况下调用时,X509Certificate2 构造函数将字节数组解释为文件名,即使documentation 表明它应该只接受一个字节数组。
我通过导入来让它在没有密码的情况下工作。
$certbytearray=[System.Convert]::FromBase64String($OctopusParameters["mycert.Pfx"])
$mycert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$mycert.import($certbytearray)
write-host $mycert.ThumbPrint
if ($mycert.HasPrivateKey)
{ write-host "has private key"}