Fonction CertGetStoreProperty (wincrypt.h)

La fonction CertGetStoreProperty récupère une propriété de magasin.

Syntaxe

BOOL CertGetStoreProperty(
  [in]      HCERTSTORE hCertStore,
  [in]      DWORD      dwPropId,
  [out]     void       *pvData,
  [in, out] DWORD      *pcbData
);

Paramètres

[in] hCertStore

Handle d’un magasin de certificats ouvert.

[in] dwPropId

Indique l’une d’une plage de propriétés de magasin. Il existe une propriété de magasin prédéfinie, CERT_STORE_LOCALIZED_NAME_PROP_ID, le nom localisé du magasin.

Les propriétés définies par l’utilisateur doivent se trouver en dehors de la plage actuelle de valeurs pour les propriétés de contexte prédéfinies. Actuellement, les valeurs dwPropId définies par l’utilisateur commencent à 4 096.

[out] pvData

Pointeur vers une mémoire tampon qui reçoit les données comme déterminé par dwPropId. Par CERT_STORE_LOCALIZED_NAME_PROP_ID, il s’agit du nom localisé du magasin et pvData pointe vers une chaîne de caractères larges Unicode terminée par null. Pour les autres dwPropIds, pvData pointe vers un tableau d’octets.

Ce paramètre peut avoir la valeur NULL pour définir la taille de ces informations à des fins d’allocation de mémoire. Pour plus d’informations, consultez Récupération de données de longueur inconnue.

[in, out] pcbData

Pointeur vers une valeur DWORD qui spécifie la taille, en octets, de la mémoire tampon pvData . Lorsque la fonction retourne, la valeur DWORD contient le nombre d’octets stockés dans la mémoire tampon.

Valeur retournée

Si la fonction réussit, la fonction retourne une valeur différente de zéro.

Si la fonction échoue, elle retourne zéro.

Si la propriété store est trouvée, la fonction retourne une valeur différente de zéro, pvData pointe vers la propriété et pcbData pointe sur la longueur de la chaîne. Si la propriété store est introuvable, la fonction retourne zéro et GetLastError renvoie CRYPT_E_NOT_FOUND.

Remarques

Les identificateurs de propriétés du magasin sont des propriétés applicables à l’ensemble d’un magasin. Il ne s’agit pas de propriétés d’un certificat individuel, d’une liste de révocation de certificats (CRL) ou d’un contexte de liste d’approbation de certificat (CTL). Actuellement, aucune propriété de magasin n’est conservée.

Pour rechercher le nom localisé d’un magasin, vous pouvez également utiliser la fonction CryptFindLocalizedName .

Exemples

L’exemple suivant illustre l’interrogation d’un magasin pour sa propriété de nom local. Un code similaire peut être utilisé pour récupérer d’autres propriétés de magasin. Pour obtenir un exemple complet qui utilise cette fonction, consultez Exemple de programme C : Définition et obtention des propriétés du magasin de certificats.

#include <windows.h>
#include <stdio.h>
#include <Wincrypt.h>


//--------------------------------------------------------------------
// Declare and initialize variables.
void *pvData = NULL;
DWORD cbData = 0;

//--------------------------------------------------------------------
// Call CertGetStoreProperty a first time
// to get the length of the store name string to be returned.
// hCertStore is a previously assigned HCERTSTORE variable that
// represents an open certificate store.
if(CertGetStoreProperty(
    hCertStore,
    CERT_STORE_LOCALIZED_NAME_PROP_ID,
    NULL,     // NULL on the first call  
              // to establish the length of the string
              // to be returned
    &cbData))
{
     printf("The length of the property is %d. \n",cbData);
}
else
{
     printf("The length of the property was not calculated.\n");
     exit(1);
}

//--------------------------------------------------------------------
// cbData is the length of a string to be allocated. 
// Allocate the space for the string and call the function a 
// second time.
if(pvData = malloc(cbData))
{
     printf("%d bytes of memory allocated.\n",cbData);
}
else
{
     printf("Memory was not allocated.\n");
     exit(1);
}

// Call CertGetStoreProperty a second time
// to copy the local store name into the pvData buffer.
if(CertGetStoreProperty(
    hCertStore,
    CERT_STORE_LOCALIZED_NAME_PROP_ID,
    pvData,
    &cbData))
{
     printf("The localized name is %S.\n",pvData);
}
else
{
     printf("CertGetStoreProperty failed.\n");
     exit(1);
}

// Free memory when done.
if (pvData)
    free(pvData);

Configuration requise

Condition requise Valeur
Client minimal pris en charge Windows XP [applications de bureau | applications UWP]
Serveur minimal pris en charge Windows Server 2003 [applications de bureau | applications UWP]
Plateforme cible Windows
En-tête wincrypt.h
Bibliothèque Crypt32.lib
DLL Crypt32.dll

Voir aussi

CertSetStoreProperty

Fonctions du magasin de certificats