2016-10-02 56 views
-2

我需要使用PersistKeySet和Exportable选项导入p12证书集合。只获得一个选项。 [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::"Exportable, PersistKeySet")不起作用。如何正确地做到这一点?使用PersistKeySet和Exportable选项导入p12收集证书

我的功能:

function ImportEASCert($strCertPath, $strCertPass) 
{ 
    $fOk = Test-Path "$strCertPath" 
    if ($fOk) 
    { 
     $bytes = [System.IO.File]::ReadAllBytes($strCertPath) 
     $cert = New-Object system.security.cryptography.x509certificates.X509Certificate2Collection 
     $store = New-Object system.security.cryptography.X509Certificates.X509Store "My", "CurrentUser" 

     try 
     { 
      $cert.Import($bytes, $strCertPass, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeySet -bor [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet) 
      $store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite) 

      foreach ($D in $cert) 
      { 
       $store.Add($d) 
       $d.SerialNumber 
      } 

      $store.Close() 
     } 
     catch 
     { 
      return "0" 
     } 
    } 
    else 
    { 
     return "0" 
    } 
} 
+0

的回答你的问题已经在你的代码。请仔细看看“MachineKeySet”和“PersistKeySet”标记是如何组合的。 –

回答

0

只是删除双冒号和类型标志引号:

[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]"Exportable, PersistKeySet" 
+0

它现在有效。非常感谢你的帮助 –