Example #1
0
        private string dereferenceURI(XmlNode reference)
        {
            XmlAttribute uriAttr = (XmlAttribute)reference.Attributes.GetNamedItem("URI");
            string id = uriAttr.Value.Replace("#", "");

            if (id == "Signature20140325080345213SignatureProperties")
                id = id;

            XmlNode digestMethNode = reference.SelectSingleNode("ds:DigestMethod", xNS);
            XmlAttribute digestMethNode_alg = (XmlAttribute)digestMethNode.Attributes.GetNamedItem("Algorithm");
            string alg = digestMethNode_alg.Value;
            XmlNode digestValNode = reference.SelectSingleNode("ds:DigestValue", xNS);
            string digestValue = digestValNode.InnerText;

            //ak ide o manifest -> kanonikalizacia a overenie odtlacku
            if (id.StartsWith("ManifestObject"))
            {
                XmlNode manifestNode = xSignature.SelectSingleNode("//ds:Manifest[@Id='" + id + "']", xNS);
                string s = manifestNode.OuterXml;

                // The XmlDsigC14NTranswill strip the UTF8 BOM
                using (MemoryStream msIn = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(s)))
                {
                    XmlDsigC14NTransform t = new XmlDsigC14NTransform(true);
                    t.LoadInput(msIn);

                    HashAlgorithm hash = null;
                    switch (alg)
                    {
                        case "http://www.w3.org/2000/09/xmldsig#sha1":
                            hash = new System.Security.Cryptography.SHA1Managed();
                            break;
                        case "http://www.w3.org/2001/04/xmldsig-more#sha224":
                            //hash = new System.Security.Cryptography.SH();
                            break;
                        case "http://www.w3.org/2001/04/xmlenc#sha256":
                            hash = new System.Security.Cryptography.SHA256Managed();
                            break;
                        case "http://www.w3.org/2001/04/xmldsig-more#sha384":
                            hash = new System.Security.Cryptography.SHA384Managed();
                            break;
                        case "http://www.w3.org/2001/04/xmlenc#sha512":
                            hash = new System.Security.Cryptography.SHA512Managed();
                            break;
                    }

                    if (hash == null)
                        return "hash algorithm ERROR (" + alg + ")";

                    byte[] digest = t.GetDigestedOutput(hash);
                    //string result = BitConverter.ToString(digest).Replace("-", String.Empty);
                    string result = Convert.ToBase64String(digest);
                    if (result.Equals(digestValue))
                        return string.Empty;
                    else
                    {
                       return  "digest value ERROR";
                    }

                }
            }

            return string.Empty;

            //throw new NotImplementedException();
        }