我有一个.crt和.key文件,我使用OpenSSL创建一个.pfx文件。我试图使用PowerShell将.pfx文件导入Cert:\LocalMachine\My,然后将该证书用于OpenVPN。使用以下代码,在导入时不会出现任何错误:
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.import("$env:TEMP\$site.pfx", $certPassword, "PersistKeySet")
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("My", "LocalMachine")
$store.open("MaxAllowed")
$store.add($cert)
$store.close()我可以在MMC中看到证书,但是OpenVPN的日志文件显示:
错误:C 5066064:microsoft cryptoapi:CryptAcquireCertificatePrivateKey:Keyset不存在
我尝试过$certPassword作为字符串和安全字符串。当我通过GUI导入证书(从$certPassword内容复制密码)时,OpenVPN将正常启动。
我也尝试过这个代码,但是看到了相同的行为:
Import-PfxCertificate -Password ($certPassword | ConvertTo-SecureString -AsPlainText -Force) -CertStoreLocation Cert:\LocalMachine\My -FilePath $env:temp\$site.pfx最后,我正在运行PowerShell会话。
我做错什么了?谢谢。
发布于 2018-05-02 16:22:58
由于要将证书添加到LocalMachine\My存储区,所以您可能希望使用X509KeyStorageFlags.MachineKeySet导入它
那可能是
$cert.import("$env:TEMP\$site.pfx", $certPassword, "PersistKeySet | MachineKeySet")但是我实际上并不了解PowerShell,所以我也不知道标志语法。
第二种可能是PFX导入将密钥保存在CNG下,但OpenVPN没有使用“我知道CNG是什么意思”标志。在使用openssl构建PFX时,可以通过指定CSP值使导入加载成为CAPI中的键。
openssl pkcs12 -export ... -CSP "Microsoft Enhanced RSA and AES Cryptographic Provider"https://stackoverflow.com/questions/50138976
复制相似问题