![在 Windows 上从命令提示符导入带有私钥的自签名证书](https://linux22.com/image/1465726/%E5%9C%A8%20Windows%20%E4%B8%8A%E4%BB%8E%E5%91%BD%E4%BB%A4%E6%8F%90%E7%A4%BA%E7%AC%A6%E5%AF%BC%E5%85%A5%E5%B8%A6%E6%9C%89%E7%A7%81%E9%92%A5%E7%9A%84%E8%87%AA%E7%AD%BE%E5%90%8D%E8%AF%81%E4%B9%A6.png)
使用 inetmgr,我创建了一个包含证书公钥和私钥的 pfx 文件。现在,我尝试使用以下命令从命令提示符将 pfx 安装到另一台计算机中
certutil -p <password> -importpfx root <path_to_pfxfile>
不幸的是,这只能导入公钥。如果我使用 certmgr 管理单元,我可以导入两个密钥,但我需要能够自动执行此操作。有人可以帮忙吗?
答案1
PowerShell命令Import-PfxCertificate
可能会执行您想要的操作。
my.pfx
这会将文件中存储的证书和密钥导入到Trusted Root Certificate Authorities
本地机器的证书存储中。
Import-PfxCertificate –FilePath C:\mypfx.pfx cert:\localMachine\Root -Password $password
您可能需要进行一些尝试才能找到用于感兴趣的证书存储的名称。我通过从 UI 中复制相关存储中的证书指纹、删除空格,然后运行来做到这一点
ls|where {$_.Thumbprint -eq "<thumprint value here, with spaces removed>"}
它给了我这个作为输出的一部分。
Directory: Microsoft.PowerShell.Security\Certificate::LocalMachine\Root
答案2
certutil 不会导入私钥。您必须使用其他工具,例如 pk12util。
此问题已得到解答。请在提问前尝试找到问题的解决方案。
请参阅这个答案:https://serverfault.com/questions/647658/how-to-add-an-existing-key-to-the-certutil-key-database