厌倦了通过MMC丛林,我需要一种方法将一个给定的.cer文件(只包含一个公钥)导入机器范围的证书存储区(不知道它是如何用英语调用的,因为我使用的是本地化的版本的
Windows)进入“个人证书”文件夹. cmd.exe或PowerShell版本都可以.
Powershell解决方案,使用System.Security.Cryptograpy.X509Certificates:
$filename = "MyFileName.cer" [Reflection.Assembly]::Load("System.Security,Version=2.0.0.0,Culture=Neutral,PublicKeyToken=b03f5f7f11d50a3a") $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($filename) $store = New-Object System.Security.Cryptography.X509Certificates.X509Store([System.Security.Cryptography.X509Certificates.StoreName]::My,[System.Security.Cryptography.X509Certificates.StoreLocation]::LocalMachine) $store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite); $store.Add($cert);
很抱歉所有完整的命名空间规范,但PowerShell中没有“using”指令.