【发布时间】:2015-05-20 19:50:48
【问题描述】:
您似乎可以根据任何字符串设置有效的X509Store 对象。
例如。
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("abcdef")
我原来是用的
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("Cert:\CurrentUser\My")
认为我有一个有效的 My 存储对象,但是在调用时我一直收到异常:
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::MaxAllowed) #Exception calling "Open" with "1" argument(s): "The parameter is incorrect.
该字符串是否应采用某种格式?
编辑:
似乎字符串可以是任何东西,只要没有斜线。所以我需要使用$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("My")。
【问题讨论】:
-
看看MSDN - X509Store Class。特别是构造函数参数“名称”和“位置”。似乎有效的位置包括:“CurrentUser”和“LocalMachine”。您原来的“Cert:\CurrentUser\My”是 PowerShell 格式。我会省略 "Cert:\" PS 驱动器。
-
根据最后一条评论 $store = New-Object System.Security.Cryptography.X509Certificates.X509Store("My", "CurrentUser") 应该可以工作。
-
但该构造函数有两个参数。我在问一个字符串参数构造函数。
-
我明白了,该评论更符合您的其他问题。
-
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("My")
标签: powershell certificate x509