我需要使用 PersistKeySet 和 Exportable 选项导入 p12 证书集合。获得只使用一个选项。
[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::"Exportable, PersistKeySet")
不行。如何正确执行?
我的功能:
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"
}
}