powershell - 使用 power shell 脚本将证书导入证书存储不起作用但手动工作
问题描述
我正在创建 SSL 证书以绑定到我的网站。我正在使用 power shell 脚本来自动化我从创建到将证书导入证书存储的过程。一旦我将证书绑定到我的网站,我的网站就无法工作。但是如果我手动将证书导入证书存储并将其绑定到我的网站。我没有遇到任何问题。
我正在调用一个脚本,它将根证书添加到受信任的根,并将客户端证书添加到个人存储。
$pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2
$rootCertImportPath = $runtimeDirPath + $rootCertName
$pfx.import($rootCertImportPath,$rootCAPass,"Exportable,PersistKeySet")
$store = new-object System.Security.Cryptography.X509Certificates.X509Store(
[System.Security.Cryptography.X509Certificates.StoreName]::Root,
"localmachine"
)
$store.open("MaxAllowed")
$store.add($pfx)
$store.close()
我正在尝试使用 $pfx.import 调用导入 .cer 文件扩展名。我需要将其他参数传递给下面提到的函数吗?
$pfx.import($rootCertImportPath,$rootCAPass,"Exportable,PersistKeySet")
请帮帮我!
解决方案
您没有导入 PFX,您只导入了没有私钥的公共证书。所以正确的调用是:
$pfx.import($rootCertImportPath)
没有使用其他参数。
推荐阅读
- r - 增长率估计包中getClass("nonlinear_fit")的作用是什么?
- javascript - 将数据从 JSON 文件传递到 html
- html - Powershell 无法填写 HTML 表单
- c# - Excel Interop 将工作表的视图样式设置为普通视图
- python - Odoo 12 邮件通知
- amazon-web-services - 如何将 AWS Kinesis Video Stream(帧)发送到 EC2 实例?
- c# - 如何修改此查询以省略空格或空值?
- r - R中的pivot_wider错误加倍:“数据”中的值不是唯一标识的;输出将包含 list-cols
- sql - SQL where 语句数千个值
- bash - Bash 忽略命令行参数中的引号