Export (0) Print
Expand All

X509CertificateStore.FindCertificateBySubjectName Method

Finds a X509Certificate object in the store using the certificate's name value.

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

'Usage
Dim subjectstring As String
Dim returnValue As X509CertificateCollection
Dim x509CertificateStore1 As X509CertificateStore
returnValue = x509CertificateStore1.FindCertificateBySubjectName(subjectstring)

public X509CertificateCollection FindCertificateBySubjectName(
	string subjectstring
);
public X509CertificateCollection FindCertificateBySubjectName(
	System.String subjectstring
);
public function FindCertificateBySubjectName(
	 subjectstring : String
) : X509CertificateCollection;

Parameters

subjectstring

a string that contains the certificate's name value

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 certificate's subject name.

private Microsoft.Web.Services2.Security.X509.X509Certificate GetCertificateUsingSubjectName(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;
    string subjectName;
    if (IsTokenForSigning)
        // Specify the subject name of the client's certificate.
        subjectName = "C=US, S=WA, L=Redmond, O=Microsoft Corporation, OU=Web Services, CN=Don Funk - Client, E=jemand@Microsoft.com";
    else
        // Specify the subject name of the server's certificate.
        subjectName = "C=US, S=WA, L=Redmond, O=Microsoft Corporation, OU=Web Services, CN=Don Funk - Server, E=jemand@Microsoft.com";

    // Search the certificate store for a certifacte based on
    // the certificate's subject name.
    X509CertificateCollection certs =
        store.FindCertificateBySubjectName(subjectName);

    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;
}

Exception typeCondition
System.InvalidOperationException

The store is not yet opened.

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
Show:
© 2014 Microsoft