将证书添加到远程x509store会错过私钥

时间:2013-01-28 19:35:26

标签: x509 x509certificate2

任务是将证书导入远程服务器(win2008服务器Web版/ IIS7)。

证书位于.pfx文件中。

安装后我注意到保存在客户端服务器上的私钥(运行脚本)(在C:\ ProgramData \ Microsoft \ Crypto \ RSA \ MachineKeys中),但不在目标服务器(安装证书)上。由于此证书不能用于具有错误的站点绑定:

  

指定的登录会话不存在。它可能已经存在   终止。

因此。我可以看到证书安装在远程服务器上,但私钥不是。 我做错了什么?

Dim pathToPFXFile As String = "\\CertServer\e$\tmp\CPVanitySSLInstall.pfx" 
    Dim passwordForPFXFile As String = "xxx"
    Dim WinVanitySSLTable As Data.DataTable
    Dim cert, cert1 As X509Certificate2
    Dim certs As X509Certificate2Collection
    Dim store As X509Store

    cert = New X509Certificate2(pathToPFXFile, passwordForPFXFile, X509KeyStorageFlags.MachineKeySet Or X509KeyStorageFlags.PersistKeySet Or X509KeyStorageFlags.Exportable)
    store = New X509Store("\\DestinationServerName\My", StoreLocation.LocalMachine)
    If (cert IsNot Nothing) Then
        store.Open(OpenFlags.MaxAllowed)
        store.Add(cert)
        store.Close()
    End If

BTW当我在目标服务器上运行此脚本时,它完全按预期工作。 除此之外,我检查了对远程服务器\ DestinationServerName \ C $ \ ProgramData \ Microsoft \ Crypto \ RSA \ MachineKeys上的机器密钥存储的访问,这没关系。

1 个答案:

答案 0 :(得分:1)

您可以在Windows中使用证书管理器来验证证书是否具有关联的私钥。在列表中选择证书,然后单击打开或查看图标,如果其中有一个小键,则您有一个私钥。 如果它有私钥,请确保iis或您的asp.net应用程序有权访问它。您可以在C:\ Users \ All Users \ Microsoft \ Crypto \ RSA \ MachineKeys中找到私钥文件以检查权限。

相关问题