本文介绍了X509Store构造函数(String)的要点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎你可以根据任何字符串设置一个有效的 X509Store 对象。
eg。

  $ store = New-Object System.Security.Cryptography.X509Certificates.X509Store(abcdef)



我最初使用

  $ store = New-Object System.Security.Cryptography.X509Certificates.X509Store(Cert:\CurrentUser\My)

我认为我有一个有效的对象为我的商店,但是我不断得到异常时调用:

  $ store.Open([System.Security.Cryptography.X509Certificates.OpenFlags] :: MaxAllowed)#Exception调用打开与1参数:参数不正确。

字符串是否采用某种格式?



编辑:
看起来好像字符串可以是任何东西,只要没有斜杠因此我需要使用 $ store = New-对象System.Security.Cryptography.X509Certificates.X509Store(My)

解决方案

这里是我理解它的要点。



X509Store类有很多构造函数。



如果实例指向有效StoreLocation中的有效StoreName,那么Open方法将打开证书存储。如果StoreLocation是正确的,则Open方法还可以基于使用的标志[System.Security.Cryptography.X509Certificates.OpenFlags]创建新的存储。



如果存储实例未正确定义,打开方法将生成System.ArgumentException。



有效的StoreLocation值为




  • CurrentUser

  • LocalMachine



且有效的StoreName值为




  • AddressBook

  • AuthRoot

  • CertificateAuthority

  • 不允许

  • 我的


  • TrustedPeople

  • TrustedPublisher。



这是MSDN对(String)构造函数的说法。



使用此构造函数为当前用户使用特定X.509商店名称创建X509Store对象。要创建新商店,请指定不存在的名称。



因此,此代码应在CurrentUser中创建一个名为abcdef的新证书存储库。

  $ store = New-Object System.Security.Cryptography.X509Certificates.X509Store(abcdef)
$ openFlags = [System.Security。 Cryptography.X509Certificates.OpenFlags] :: MaxAllowed
$ store.Open($ openFlags)

可以使用MMC验证。





因此,总之,存储构造函数参数StoreName和String是可互换的。语义StoreName用于引用预定义的值,String可以指任何值。


It seems as though you can set up a valid X509Store object based on any string.eg.

$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("abcdef")

I originally was using

 $store = New-Object System.Security.Cryptography.X509Certificates.X509Store("Cert:\CurrentUser\My")

thinking I had a valid object for the My store, however I kept getting an exception when calling:

$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::MaxAllowed) #Exception calling "Open" with "1" argument(s): "The parameter is incorrect.

Is the string meant to be in a certain format?

EDIT:It seems as though the string can be anything, as long as there are no slashes. So I need to use $store = New-Object System.Security.Cryptography.X509Certificates.X509Store("My").

解决方案

After consulting MSDN X509Store Class documentation here is the gist of my understanding of it.

There are a number of constructors for X509Store Class. After defining an instance of the class, this can then be opened using the Open method.

If the instance points to a valid StoreName in a valid StoreLocation the Open method will open a certificate store. The Open method can also create a new store based on flags [System.Security.Cryptography.X509Certificates.OpenFlags] used, if the StoreLocation is correct.

If the store instance is not defined correctly, open method it will generate a System.ArgumentException.

Valid StoreLocation values are

  • CurrentUser
  • LocalMachine

and valid StoreName values are

  • AddressBook
  • AuthRoot
  • CertificateAuthority
  • Disallowed
  • My
  • Root
  • TrustedPeople
  • TrustedPublisher.

This is what MSDN has to say about the (String) constructor.

"Use this constructor to create an X509Store object using a particular X.509 store name for the current user. To create a new store, specify a name that does not exist. A new store will be created with that name."

So this code should create a new certificate store in "CurrentUser" called "abcdef".

$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("abcdef")
$openFlags = [System.Security.Cryptography.X509Certificates.OpenFlags]::MaxAllowed
$store.Open($openFlags)

It can be verified using MMC.

So, in conclusion, store constructor parameters "StoreName" and "String" are interchangeable. Semantically "StoreName" is used in reference to predefined values and "String" can refer to any value.

这篇关于X509Store构造函数(String)的要点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 13:47