CertComparePublicKeyInfo

The CertComparePublicKeyInfo function compares two public keys to determine whether they are identical. The public key blobs must be in their encoded representation.

#include <wincrypt.h>
BOOL WINAPI CertComparePublicKeyInfo(
  DWORD dwCertEncodingType,           // in
  PCERT_PUBLIC_KEY_INFO pPublicKey1,  // in
  PCERT_PUBLIC_KEY_INFO pPublicKey2   // in
);
 

Parameters

dwCertEncodingType
The type of encoding used on the certificate. Currently defined certificate encoding types are shown in the following table:
Encoding type Value
X509_ASN_ENCODING 0x00000001

pPublicKey1
A pointer to the CERT_PUBLIC_KEY_INFO for the first public key in the comparison.
pPublicKey2
A pointer to the CERT_PUBLIC_KEY_INFO for the second public key in the comparison.

Return Values

TRUE if the public keys are identical.

Example

// EXAMPLE CODE FOR USING CertComparePublicKeyInfo() to 
// compare two public keys to determine whether they are identical.

// Assume that the application has a pointer to both public keys to 
// compare (pPublicKey1, pPublicKey2) and that X509_ASN_ENCODING was used.

// Set up the variables.
PCERT_PUBLIC_KEY_INFO pPublicKey1, pPublicKey2; // Initialized elsewhere
BOOL Return;

Return = CertComparePublicKeyInfo(
            X509_ASN_ENCODING, pPublicKey1, pPublicKey2);

if (Return == TRUE) {
    // The public keys are identical, continue as desired.
}
 

QuickInfo

  Windows NT: Requires version 4.0 SP3 or later. Available also in IE 3.02 and later.
  Windows: Requires Windows 98 (or Windows 95 with IE 3.02 or later).
  Windows CE: Unsupported.
  Header: Declared in wincrypt.h.
  Import Library: Use crypt32.lib.