加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 00:04:27 所属栏目:Windows 来源:网络整理
导读:厌倦了通过MMC丛林,我需要一种方法将一个给定的.cer文件(只包含一个公钥)导入机器范围的证书存储区(不知道它是如何用英语调用的,因为我使用的是本地化的版本的 Windows)进入“个人证书”文件夹. cmd.exe或PowerShell版本都可以. Powershell解决方案,使用Syst
厌倦了通过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”指令.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读