예제 #1
0
        private Xades(XmlElement element)
        {
            _document  = element.OwnerDocument;
            _signedXml = new XadesSignedXml(_document);
            _signedXml.LoadXml(element);

            CanonicalizationMethod = _signedXml.SignedInfo.CanonicalizationMethod;
            SignatureMethod        = _signedXml.SignedInfo.SignatureMethod;

            XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());

            nsm.AddNamespace("ds", SignedXml.XmlDsigNamespaceUrl);
            nsm.AddNamespace("xades", XadesNamespaceUrl);

            // find the xades reference
            _referenceIndex = new Dictionary <Reference, XadesReference>();
            References      = new List <XadesReference>();
            foreach (Reference reference in _signedXml.SignedInfo.References)
            {
                if (reference.Type == Xades.XadesReferenceType && reference.Uri[0] == '#')
                {
                    XmlElement signedProperties = element.SelectSingleNode($"//xades:SignedProperties[@Id='{reference.Uri.Substring(1)}']", nsm) as XmlElement;
                    if (signedProperties != null)
                    {
                        _signedProperties          = signedProperties;
                        _referenceIndex[reference] = null;
                        continue;
                    }
                }
                // external reference
                XadesReference xadesReference = new XadesReference(reference);
                _referenceIndex[reference] = xadesReference;
                References.Add(xadesReference);
            }
            if (_signedProperties == null)
            {
                return;
            }

            // parse signature policy
            SignatureProperties = new XadesSignatureProperties(_signedProperties, nsm);

            // create xades files
            foreach (XadesReference item in References)
            {
                item.ParseProperties(_signedProperties, nsm);
            }
        }
예제 #2
0
        private Xades(XmlDocument document, XmlElement signatureParent)
        {
            _document        = document;
            _signatureParent = signatureParent;

            SignatureProperties = new XadesSignatureProperties();
            References          = new List <XadesReference>();

            // set defaults
            SignatureType = SignatureType.Xades;

            CanonicalizationMethod = SignedXml.XmlDsigExcC14NWithCommentsTransformUrl;
            DigestMethod           = SignedXml.XmlDsigSHA256Url;
            SignatureMethod        = SignedXml.XmlDsigRSASHA256Url;

            XadesTransformChain = new TransformChain();
            XadesTransformChain.Add(new XmlDsigExcC14NTransform());
            XadesDigestMethod = SignedXml.XmlDsigSHA256Url;
        }