1 out of 1 rated this helpful - Rate this topic

X509CertificateStore.FindCertificateByKeyIdentifier Method

Finds a X509Certificate object in the store using the specified key identifier.

Namespace: Microsoft.Web.Services2.Security.X509
Assembly: Microsoft.Web.Services2 (in microsoft.web.services2.dll)

'Usage
Dim keyIdentifier() As Byte
Dim returnValue As X509CertificateCollection
Dim x509CertificateStore1 As X509CertificateStore
returnValue = x509CertificateStore1.FindCertificateByKeyIdentifier(keyIdentifier)
public X509CertificateCollection FindCertificateByKeyIdentifier(
	byte[] keyIdentifier
);
public X509CertificateCollection FindCertificateByKeyIdentifier(
	ubyte[] keyIdentifier
);
public function FindCertificateByKeyIdentifier(
	 keyIdentifier : Byte[]
) : X509CertificateCollection;

Parameters

keyIdentifier

A byte array containing a unique identifier for a specific X.509 certificate.

Return Value

A X509CertificateCollection that contains the search result.

The following code example opens the My certificate store for the currently logged in user and then searches for a particular X.509 certificate using the certificate's key identifier.

private Microsoft.Web.Services2.Security.X509.X509Certificate GetCertificateUsingKeyIdentifer(bool IsTokenForSigning)
{
    // Open up the My certificate store for the currently logged
    // in user.
    X509CertificateStore store;
    store = X509CertificateStore.CurrentUserStore(
        X509CertificateStore.MyStore);
    bool open = store.OpenRead();

    Microsoft.Web.Services2.Security.X509.X509Certificate cert = null;
    byte[] certKeyID;
    if (IsTokenForSigning)
        certKeyID = new byte[]{0x48, 0x1b, 0xe8, 0xec, 0xbd, 0x32, 0xc, 0xd6, 0x39, 0xa8, 0x9b, 0xce, 0xea, 0x5a, 0x2a, 0xe4, 0x66, 0x76, 0x62, 0x42};
    else
        certKeyID = new byte[]{0xe8, 0x8f, 0xe1, 0x8a, 0x62, 0x6, 0xd6, 0x1a, 0x85, 0xf6, 0x5a, 0x26, 0x81, 0x0, 0x56, 0x29, 0xb1, 0x8a, 0x29, 0x47};

    // Search for a certifacte based on the
    // certificate's key identifier.
    X509CertificateCollection certs =
        store.FindCertificateByKeyIdentifier(certKeyID);
        
    if (certs.Count > 0)
        // Obtain the first matching certificate.
        cert = ((Microsoft.Web.Services2.Security.X509.X509Certificate) certs[0]);
    else
        // No certificates matched the search criteria.
        cert = null;

    // Close the X.509 certificate store.
    if (store != null) { store.Close(); }

    return cert;
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Development Platforms

Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Longhorn, and Windows 2000

Target Platforms

Windows 2000, Windows 2000 Server, Windows 2000 Advanced Server, Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Longhorn, Pocket PC, Windows CE, Smart Phone
Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.