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)
Assembly: Microsoft.Web.Services2 (in microsoft.web.services2.dll)
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; }