iTextSharp.text.pdf.security.MakeXmlSignature.GenerateCustomReference C# (CSharp) Method

GenerateCustomReference() private static method

private static GenerateCustomReference ( XmlDocument doc, XmlElement signedElement, String uri, String type, String id ) : XmlElement
doc XmlDocument
signedElement XmlElement
uri String
type String
id String
return XmlElement
        private static XmlElement GenerateCustomReference(XmlDocument doc, XmlElement signedElement, String uri, String type, String id) {

            XmlElement reference = doc.CreateElement("Reference", SecurityConstants.XMLDSIG_URI);
            if (uri == null)
                uri = string.Empty;
            reference.SetAttribute("URI", uri);
            if(type != null)
                reference.SetAttribute("Type", type);
            if(id != null)
                reference.SetAttribute("Id", id);
            XmlElement xpathSelect = (XmlElement)signedElement.CloneNode(true);
            XPathNavigator xpathSelectNavigator = xpathSelect.CreateNavigator();
            NormalizeNamespaces(doc.DocumentElement.CreateNavigator(), xpathSelectNavigator);
            xpathSelectNavigator.CreateAttribute("xmlns", "xades", SecurityConstants.XMLNS_URI, SecurityConstants.XADES_132_URI);
            xpathSelectNavigator.CreateAttribute("xmlns", "", SecurityConstants.XMLNS_URI, SecurityConstants.XMLDSIG_URI);
            
            XmlDocument digestDoc = new XmlDocument(doc.NameTable);
            digestDoc.LoadXml(xpathSelect.OuterXml);

            byte[] md = CalculateC14nDigest(digestDoc, new SHA1Managed());

            XmlElement digestMethod = doc.CreateElement("DigestMethod", SecurityConstants.XMLDSIG_URI);
            digestMethod.SetAttribute("Algorithm", SecurityConstants.XMLDSIG_URI_SHA1);
            reference.AppendChild(digestMethod);

            XmlElement digestValue = doc.CreateElement("DigestValue", SecurityConstants.XMLDSIG_URI);

            digestValue.AppendChild(doc.CreateTextNode(Convert.ToBase64String(md)));

            reference.AppendChild(digestValue);
            return reference;
        }