Пример #1
0
        public XmlDocument Send(XmlDocument message, MessageType messageType)
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol  = SetCryptoConfig.SetTLSProtocol();
            ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, sslPolicyErrors) => { return(true); });

            HttpWebRequest request = this.createWebRequest(message, messageType);

            request.ClientCertificates.Add(this.settings.Certificate);
            using (Stream stream = request.GetRequestStream())
            {
                StreamWriter sw = new StreamWriter(stream, new System.Text.UTF8Encoding(false, true));
                message.Save(sw);
            }

            XmlDocument result = XmlHelperFunctions.CreateNewXmlDocument();

            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                {
                    string soapResult = rd.ReadToEnd();

                    result.LoadXml(soapResult);
                }
            }

            return(result);
        }
Пример #2
0
        public void Sign(XmlDocument message, MessageType messageType)
        {
            XmlNode mainNode = this.getMainNode(message, messageType);

            if (mainNode == null)
            {
                return;
            }

            SetCryptoConfig.SetAlgorithm();

            SignedXml signedXml = new SignedXml(message);

            signedXml.SigningKey = this.settings.CryptoProvider;
            signedXml.AddReference(this.getReference(mainNode));
            signedXml.KeyInfo = this.getKeyInfo();
            signedXml.SignedInfo.SignatureMethod = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
            signedXml.ComputeSignature();

            XmlElement xmlDigitalSignature = signedXml.GetXml();

            mainNode.AppendChild(xmlDigitalSignature);
        }