命令行界面 – 从Windows命令行导入.cer证书

厌倦了通过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”指令.

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...