powershell - 无法使用 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
解决方案
在浏览了 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)
推荐阅读
- python - 从列表列表创建多个类
- angular7 - 相机在 ionic 4 Project 中捕获图像。如何添加地理定位(纬度和经度)该图像保存在带有位置的电话库中
- magento - 我们升级网站时会创建以下错误日志。如何解决?
- python - 如何在 python dask 中使用 group by describe 和 unstack 操作?
- python - 如何将 curl 示例转换为 Pycurl
- python - 如何在 Django 中使用内联表单集删除模型对象
- javascript - axios如何将Windows身份验证标头发送到API
- python - 使用 numpy 线性代数计算二次响应
- python - 是否可以在中间件中过滤掉一些数据库行?
- java - 为什么在这里初始化 ListNode 两次?