Import pfx file into particular certificate store from command line

后端 未结 7 1511
时光取名叫无心
时光取名叫无心 2021-01-30 17:12

It\'s relatively easy to import a certificate into the user\'s personal store from a pfx file by using CertUtil:

certutil –f –p [certificate_password] –importpfx         


        
7条回答
  •  你的背包
    2021-01-30 17:37

    To anyone else looking for this, I wasn't able to use certutil -importpfx into a specific store, and I didn't want to download the importpfx tool supplied by jaspernygaard's answer in order to avoid the requirement of copying the file to a large number of servers. I ended up finding my answer in a powershell script shown here.

    The code uses System.Security.Cryptography.X509Certificates to import the certificate and then moves it into the desired store:

    function Import-PfxCertificate { 
    
        param([String]$certPath,[String]$certRootStore = “localmachine”,[String]$certStore = “My”,$pfxPass = $null) 
        $pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2 
    
        if ($pfxPass -eq $null) 
        {
            $pfxPass = read-host "Password" -assecurestring
        } 
    
        $pfx.import($certPath,$pfxPass,"Exportable,PersistKeySet") 
    
        $store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore) 
        $store.open("MaxAllowed") 
        $store.add($pfx) 
        $store.close() 
    }
    

提交回复
热议问题