This documentation is archived and is not being maintained.

X509IssuerSerial Structure

Represents the <X509IssuerSerial> element of an XML digital signature.

Namespace:  System.Security.Cryptography.Xml
Assembly:  System.Security (in System.Security.dll)

[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public struct X509IssuerSerial

The X509IssuerSerial type exposes the following members.

Public propertyIssuerNameGets or sets an X.509 certificate issuer's distinguished name.
Public propertySerialNumberGets or sets an X.509 certificate issuer's serial number.

Public methodEqualsIndicates whether this instance and a specified object are equal. (Inherited from ValueType.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeReturns the hash code for this instance. (Inherited from ValueType.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns the fully qualified type name of this instance. (Inherited from ValueType.)

The X509IssuerSerial structure represents the <X509IssuerSerial> element of an XML digital signature defined by the XML digital signature specification. The <X509IssuerSerial> element is the subelement of the <X509Data> element that contains an X.509v3 certificate issuer's distinguished name and serial number pair. The distinguished name and serial number pair help identify a specific X.509v3 certificate.

The issuer of an X.509 certificate is the name of the certification authority that issued the certificate. Certification authorities assign each certificate they issue a unique serial number for identification purposes.

Use the X509IssuerSerial structure to specify a certificate issuer's distinguished name and serial number pair when using the KeyInfoX509Data class. You can add an X509IssuerSerial structure to the KeyInfoX509Data class using the IssuerSerials property. Alternatively, you can add string values that represent the X.509 certificate issuer's distinguished name and serial number pair using the AddIssuerSerial method.

For more information about the <X509IssuerSerial> element, see the World Wide Web Consortium (W3C) specification at


The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: MayLeakOnAbort. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

The following code example demonstrates how to sign and verify an XML document using an X.509 certificate from a certificate store. This example saves key information to the signed document using the X509IssuerSerial object.

// This example signs an XML file using an
// envelope signature. It then verifies the 
// signed XML.
// You must have a certificate with a subject name
// of "CN=XMLDSIG_Test" in the "My" certificate store. 
// Run the following command to create a certificate
// and place it in the store.
// makecert -r -pe -n "CN=XMLDSIG_Test" -b 01/01/2005 -e 01/01/2010 -sky signing -ss my

using System;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Xml;

public class SignVerifyEnvelope

    public static void Main(String[] args)

        string Certificate = "CN=XMLDSIG_Test";


            // Create an XML file to sign.
            Console.WriteLine("New XML file created.");

            // Sign the XML that was just created and save it in a 
            // new file.
            SignXmlFile("Example.xml", "SignedExample.xml", Certificate);
            Console.WriteLine("XML file signed.");

            if (VerifyXmlFile("SignedExample.xml", Certificate))
                Console.WriteLine("The XML signature is valid.");
                Console.WriteLine("The XML signature is not valid.");
        catch (CryptographicException e)

    // Sign an XML file and save the signature in a new file.
    public static void SignXmlFile(string FileName, string SignedFileName, string SubjectName)
        if (null == FileName)
            throw new ArgumentNullException("FileName");
        if (null == SignedFileName)
            throw new ArgumentNullException("SignedFileName");
        if (null == SubjectName)
            throw new ArgumentNullException("SubjectName");

        // Load the certificate from the certificate store.
        X509Certificate2 cert = GetCertificateBySubject(SubjectName);

        // Create a new XML document.
        XmlDocument doc = new XmlDocument();

        // Format the document to ignore white spaces.
        doc.PreserveWhitespace = false;

        // Load the passed XML file using it's name.
        doc.Load(new XmlTextReader(FileName));

        // Create a SignedXml object.
        SignedXml signedXml = new SignedXml(doc);

        // Add the key to the SignedXml document. 
        signedXml.SigningKey = cert.PrivateKey;

        // Create a reference to be signed.
        Reference reference = new Reference();
        reference.Uri = "";

        // Add an enveloped transformation to the reference.
        XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();

        // Add the reference to the SignedXml object.

        // Create a new KeyInfo object.
        KeyInfo keyInfo = new KeyInfo();

        // Load the certificate into a KeyInfoX509Data object
        // and add it to the KeyInfo object.
        // Create an X509IssuerSerial object and add it to the
        // KeyInfoX509Data object.

        KeyInfoX509Data kdata = new KeyInfoX509Data(cert);

        X509IssuerSerial xserial;

        xserial.IssuerName = cert.IssuerName.ToString();
        xserial.SerialNumber = cert.SerialNumber;

        kdata.AddIssuerSerial(xserial.IssuerName, xserial.SerialNumber);


        // Add the KeyInfo object to the SignedXml object.
        signedXml.KeyInfo = keyInfo;

        // Compute the signature.

        // Get the XML representation of the signature and save
        // it to an XmlElement object.
        XmlElement xmlDigitalSignature = signedXml.GetXml();

        // Append the element to the XML document.
        doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, true));

        if (doc.FirstChild is XmlDeclaration)

        // Save the signed XML document to a file specified
        // using the passed string.
        using (XmlTextWriter xmltw = new XmlTextWriter(SignedFileName, new UTF8Encoding(false)))


    // Verify the signature of an XML file against an asymetric 
    // algorithm and return the result.
    public static Boolean VerifyXmlFile(String FileName, String CertificateSubject)
        // Check the args.
        if (null == FileName)
            throw new ArgumentNullException("FileName");
        if (null == CertificateSubject)
            throw new ArgumentNullException("CertificateSubject");

        // Load the certificate from the store.
        X509Certificate2 cert = GetCertificateBySubject(CertificateSubject);

        // Create a new XML document.
        XmlDocument xmlDocument = new XmlDocument();

        // Load the passed XML file into the document. 

        // Create a new SignedXml object and pass it
        // the XML document class.
        SignedXml signedXml = new SignedXml(xmlDocument);

        // Find the "Signature" node and create a new
        // XmlNodeList object.
        XmlNodeList nodeList = xmlDocument.GetElementsByTagName("Signature");

        // Load the signature node.

        // Check the signature and return the result.
        return signedXml.CheckSignature(cert, true);


    public static X509Certificate2 GetCertificateBySubject(string CertificateSubject)
        // Check the args.
        if (null == CertificateSubject)
            throw new ArgumentNullException("CertificateSubject");

        // Load the certificate from the certificate store.
        X509Certificate2 cert = null;

        X509Store store = new X509Store("My", StoreLocation.CurrentUser);

            // Open the store.
            store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

            // Get the certs from the store.
            X509Certificate2Collection CertCol = store.Certificates;

            // Find the certificate with the specified subject.
            foreach (X509Certificate2 c in CertCol)
                if (c.Subject == CertificateSubject)
                    cert = c;

            // Throw an exception of the certificate was not found.
            if (cert == null)
                throw new CryptographicException("The certificate could not be found.");
            // Close the store even if an exception was thrown.

        return cert;

    // Create example data to sign.
    public static void CreateSomeXml(string FileName)
        // Check the args.
        if (null == FileName)
            throw new ArgumentNullException("FileName");

        // Create a new XmlDocument object.
        XmlDocument document = new XmlDocument();

        // Create a new XmlNode object.
        XmlNode node = document.CreateNode(XmlNodeType.Element, "", "MyElement", "samples");

        // Add some text to the node.
        node.InnerText = "Example text to be signed.";

        // Append the node to the document.

        // Save the XML document to the file name specified.
        using (XmlTextWriter xmltw = new XmlTextWriter(FileName, new UTF8Encoding(false)))

// This code example displays the following to the console:
// New XML file created.
// XML file signed.
// The XML signature is valid.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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