コード例 #1
0
        /// <summary>
        /// Метод добавляет в XML тэг <ds:Reference></Reference>
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="signedXml"></param>
        /// <param name="customTag"></param>
        /// <param name="customNamespace"></param>
        /// <param name="precedingSibling"></param>
        /// <returns></returns>
        internal static SignedXml AddReference(XmlDocument doc, SignedXml signedXml, IntPtr certificate, bool signWithId, Mr mr,
                                               SignedTag elemForSign,
                                               ref int idCounter,
                                               string tagForSign,
                                               string tagForSignNamespaceUri,
                                               string namespaceIdAttr = "",
                                               string customTag       = "",
                                               string customNamespace = ""
                                               )
        {
            Reference reference = new Reference();
            string    id        = string.Empty;

            if (elemForSign == SignedTag.CustomTag && string.IsNullOrEmpty(customTag) != true)
            {
                id = SmevXmlHelper.GetElemId(doc, customTag, customNamespace, signWithId);

                if (string.IsNullOrEmpty(id) && signWithId)
                {
                    if (mr == Mr.MR300)
                    {
                        SmevXmlHelper.SetElemId(doc, customTag, NamespaceUri.WSSoap11, signWithId, mr, ref idCounter);
                    }
                    else
                    {
                        id = "#" + SmevXmlHelper.SetElemId(doc, customTag, tagForSignNamespaceUri, signWithId, mr, ref idCounter, "", namespaceIdAttr);
                    }
                }
            }
            else
            {
                id = SmevXmlHelper.GetElemId(doc, tagForSign, tagForSignNamespaceUri, signWithId);

                if (string.IsNullOrEmpty(id) && signWithId)
                {
                    if (mr == Mr.MR300)
                    {
                        id = SmevXmlHelper.SetElemId(doc, tagForSign, tagForSignNamespaceUri, signWithId, mr, ref idCounter);
                    }
                    else
                    {
                        id = "#" + SmevXmlHelper.SetElemId(doc, tagForSign, tagForSignNamespaceUri, signWithId, mr, ref idCounter, "", namespaceIdAttr);
                    }
                }
            }

            reference.Uri          = (signWithId) ? id : string.Empty;
            reference.DigestMethod = SignServiceUtils.GetDigestMethod(SignServiceUtils.GetAlgId(certificate));

            if (string.IsNullOrEmpty(customTag) != true && elemForSign == SignedTag.CustomTag)
            {
                XmlDsigEnvelopedSignatureTransform envelop = new XmlDsigEnvelopedSignatureTransform();
                reference.AddTransform(envelop);
            }

            XmlDsigExcC14NTransform c14 = new XmlDsigExcC14NTransform();

            reference.AddTransform(c14);

            if (mr == Mr.MR300)
            {
                SmevTransformAlg smevTransform = new SmevTransformAlg();
                reference.AddTransform(smevTransform);
            }

            signedXml.AddReference(reference);

            return(signedXml);
        }