Cet article a fait l’objet d’une traduction automatique. Pour afficher l’article en anglais, activez la case d’option Anglais. Vous pouvez également afficher le texte anglais dans une fenêtre contextuelle en faisant glisser le pointeur de la souris sur le texte traduit.
Traduction
Anglais

X509Store classe

 

Date de publication : novembre 2016

Représente un magasin X.509, magasin physique où les certificats sont conservés et gérés. Cette classe ne peut pas être héritée.

Espace de noms:   System.Security.Cryptography.X509Certificates
Assembly:  System (dans System.dll)

System.Object
  System.Security.Cryptography.X509Certificates.X509Store

public sealed class X509Store : IDisposable

NomDescription
System_CAPS_pubmethodX509Store()

Initialise une nouvelle instance de la classe X509Store à l’aide des certificats personnels du magasin de l’utilisateur actuel.

System_CAPS_pubmethodX509Store(IntPtr)

Initialise une nouvelle instance de la classe X509Store en utilisant un handle Intptr vers un magasin HCERTSTORE.

System_CAPS_pubmethodX509Store(StoreLocation)

Initialise une nouvelle instance de la classe X509Store avec la valeur StoreLocation spécifiée.

System_CAPS_pubmethodX509Store(StoreName)

Initialise une nouvelle instance de la classe X509Store avec la valeur StoreName spécifiée.

System_CAPS_pubmethodX509Store(StoreName, StoreLocation)

Initialise une nouvelle instance de la classe X509Store à l’aide des valeurs StoreName et StoreLocation spécifiées.

System_CAPS_pubmethodX509Store(String)

Initialise une nouvelle instance de la classe X509Store avec le nom de magasin spécifié.

System_CAPS_pubmethodX509Store(String, StoreLocation)

Initialise une nouvelle instance de la classe X509Store en utilisant une chaîne qui représente une valeur de l’énumération StoreName et une valeur de l’énumération StoreLocation.

NomDescription
System_CAPS_pubpropertyCertificates

Retourne une collection de certificats se trouvant dans un magasin de certificats X.509.

System_CAPS_pubpropertyLocation

Obtient l'emplacement du magasin de certificats X.509.

System_CAPS_pubpropertyName

Obtient le nom du magasin de certificats X.509.

System_CAPS_pubpropertyStoreHandle

Obtient un handle IntPtr pour un magasin HCERTSTORE.

NomDescription
System_CAPS_pubmethodAdd(X509Certificate2)

Ajoute un certificat à un magasin de certificats X.509.

System_CAPS_pubmethodAddRange(X509Certificate2Collection)

Ajoute une collection de certificats à un magasin de certificats X.509.

System_CAPS_pubmethodClose()

Ferme un magasin de certificats X.509.

System_CAPS_pubmethodDispose()

Libère les ressources utilisées par ce X509Store.

System_CAPS_pubmethodEquals(Object)

Détermine si l'objet spécifié est identique à l'objet actuel.(Hérité de Object.)

System_CAPS_pubmethodGetHashCode()

Fait office de fonction de hachage par défaut.(Hérité de Object.)

System_CAPS_pubmethodGetType()

Obtient le Type de l'instance actuelle.(Hérité de Object.)

System_CAPS_pubmethodOpen(OpenFlags)

Ouvre un magasin de certificats X.509 ou crée un magasin, selon les valeurs des indicateurs OpenFlags.

System_CAPS_pubmethodRemove(X509Certificate2)

Supprime un certificat d'un magasin de certificats X.509.

System_CAPS_pubmethodRemoveRange(X509Certificate2Collection)

Supprime une plage de certificats d'un magasin de certificats X.509.

System_CAPS_pubmethodToString()

Retourne une chaîne qui représente l'objet actuel.(Hérité de Object.)

Use this class to work with an X.509 store.

System_CAPS_importantImportant

Starting with the net_v46, this type implements the T:System.IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its M:System.IDisposable.Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the “Using an Object that Implements IDisposable” section in the T:System.IDisposable interface topic.

For apps that target the net_v452 and earlier versions, the T:System.Security.Cryptography.X509Certificates.X509Store class does not implement the T:System.IDisposable interface and therefore does not have a Dispose method.

This section contains two examples. The first example demonstrates how you can open standard X.509 stores and list the number of certificates in each.

The second example demonstrates how you can add and remove single certificates and ranges of certificates.

Example 1

This example tries to open each standard store in each standard location on the current computer. It prints a summary that shows whether each store exists and, if so, the number of certificates it contains.

The example creates an T:System.Security.Cryptography.X509Certificates.X509Store object for each combination of standard name and standard location. It calls the M:System.Security.Cryptography.X509Certificates.X509Store.Open(System.Security.Cryptography.X509Certificates.OpenFlags) method with the F:System.Security.Cryptography.X509Certificates.OpenFlags.OpenExistingOnly flag, which opens the physical store only if it already exists. If the physical store exists, the example uses the P:System.Security.Cryptography.X509Certificates.X509Store.Name, P:System.Security.Cryptography.X509Certificates.X509Store.Location, and P:System.Security.Cryptography.X509Certificates.X509Store.Certificates properties to display the number of certificates in the store.

using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

public class Example
{
    static void Main()
    {
        Console.WriteLine("\r\nExists Certs Name and Location");
        Console.WriteLine("------ ----- -------------------------");

        foreach (StoreLocation storeLocation in (StoreLocation[]) 
            Enum.GetValues(typeof(StoreLocation)))
        {
            foreach (StoreName storeName in (StoreName[]) 
                Enum.GetValues(typeof(StoreName)))
            {
                X509Store store = new X509Store(storeName, storeLocation);

                try
                {
                    store.Open(OpenFlags.OpenExistingOnly);

                    Console.WriteLine("Yes    {0,4}  {1}, {2}", 
                        store.Certificates.Count, store.Name, store.Location);
                }   
                catch (CryptographicException)
                {
                    Console.WriteLine("No           {0}, {1}", 
                        store.Name, store.Location);
                }
            }
            Console.WriteLine();
        }
    }
}

/* This example produces output similar to the following:

Exists Certs Name and Location
------ ----- -------------------------
Yes       1  AddressBook, CurrentUser
Yes      25  AuthRoot, CurrentUser
Yes     136  CA, CurrentUser
Yes      55  Disallowed, CurrentUser
Yes      20  My, CurrentUser
Yes      36  Root, CurrentUser
Yes       0  TrustedPeople, CurrentUser
Yes       1  TrustedPublisher, CurrentUser

No           AddressBook, LocalMachine
Yes      25  AuthRoot, LocalMachine
Yes     131  CA, LocalMachine
Yes      55  Disallowed, LocalMachine
Yes       3  My, LocalMachine
Yes      36  Root, LocalMachine
Yes       0  TrustedPeople, LocalMachine
Yes       1  TrustedPublisher, LocalMachine

 */

Example 2

This example opens an X.509 certificate store, adds and deletes certificates, and then closes the store. It assumes that you have three certificates to add to and remove from a local store.

using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.IO;

public class X509store2
{
	public static void Main (string[] args)
	{
		//Create new X509 store called teststore from the local certificate store.
		X509Store store = new X509Store ("teststore", StoreLocation.CurrentUser);
		store.Open (OpenFlags.ReadWrite);
		X509Certificate2 certificate = new X509Certificate2 ();

		//Create certificates from certificate files.
		//You must put in a valid path to three certificates in the following constructors.
		X509Certificate2 certificate1 = new X509Certificate2 ("c:\\mycerts\\*****.cer");
		X509Certificate2 certificate2 = new X509Certificate2 ("c:\\mycerts\\*****.cer");
		X509Certificate2 certificate5 = new X509Certificate2 ("c:\\mycerts\\*****.cer");

		//Create a collection and add two of the certificates.
		X509Certificate2Collection collection = new X509Certificate2Collection ();
		collection.Add (certificate2);
		collection.Add (certificate5);

		//Add certificates to the store.
		store.Add (certificate1);
		store.AddRange (collection);

		X509Certificate2Collection storecollection = (X509Certificate2Collection)store.Certificates;
		Console.WriteLine ("Store name: {0}", store.Name);
		Console.WriteLine ("Store location: {0}", store.Location);
		foreach (X509Certificate2 x509 in storecollection)
		{
			Console.WriteLine("certificate name: {0}",x509.Subject);
		}

		//Remove a certificate.
		store.Remove (certificate1);
		X509Certificate2Collection storecollection2 = (X509Certificate2Collection)store.Certificates;
		Console.WriteLine ("{1}Store name: {0}", store.Name, Environment.NewLine);
		foreach (X509Certificate2 x509 in storecollection2)
		{
			Console.WriteLine ("certificate name: {0}", x509.Subject);
		}

		//Remove a range of certificates.
		store.RemoveRange (collection);
		X509Certificate2Collection storecollection3 = (X509Certificate2Collection)store.Certificates;
		Console.WriteLine ("{1}Store name: {0}", store.Name, Environment.NewLine);
		if (storecollection3.Count == 0)
		{
			Console.WriteLine ("Store contains no certificates.");
		}
		else
		{
			foreach (X509Certificate2 x509 in storecollection3)
			{
				Console.WriteLine ("certificate name: {0}", x509.Subject);
			}
		}

		//Close the store.
		store.Close ();
	}	
}

.NET Framework
Disponible depuis 2.0

Tous les membres statiques publics ( Shared en Visual Basic) de ce type sont thread-safe. Les membres d’instance n’ont pas la garantie d’être thread-safe.

Retour au début
Afficher: