IX509PublicKey::ComputeKeyIdentifier method

The ComputeKeyIdentifier method creates an identifier from a 160-bit SHA-1 hash of the public key.


HRESULT ComputeKeyIdentifier(
  [in]  KeyIdentifierHashAlgorithm Algorithm,
  [in]  EncodingType               Encoding,
  [out] BSTR                       *pValue


Algorithm [in]

A value of the KeyIdentifierHashAlgorithm enumeration that specifies what hash algorithm to use to create the key identifier.

If this value is SKIHashDefault or SKIHashSha1, the identifier is created by hashing only the byte array that contains the key and excluding the Distinguished Encoding Rules (DER) tag, length, and unused bits fields.

If this value is SKIHashCapiSha1, the identifier is created by hashing the DER-encoded byte array that contains the tag, length, number of unused bits, and the public key.

Encoding [in]

An EncodingType enumeration value that specifies the type of Unicode-encoding to be applied to the hash contained in the pValue parameter. The default value is XCN_CRYPT_STRING_BASE64.

pValue [out]

Pointer to a BSTR variable that contains the key identifier.

Return value

If the function succeeds, the function returns S_OK.

If the function fails, it returns an HRESULT value that indicates the error. Possible values include, but are not limited to, those in the following table. For a list of common error codes, see Common HRESULT Values.

Return code/valueDescription

The algorithm object identifier or the public key parameters could not be found.



You must call the InitializeFromEncodedPublicKeyInfo method or the Initialize method to initialize the public key object before calling ComputeKeyIdentifier.


Minimum supported client

Windows Vista [desktop apps only]

Minimum supported server

Windows Server 2008 [desktop apps only]





See also




Community Additions