コード例 #1
0
        private SignatureStructReply CalculateSignature(string base64Message)
        {
            ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);//验证服务器证书回调自动验证


            string         url     = "https://" + SingletonInfo.GetInstance().signatureIP + ":" + SingletonInfo.GetInstance().signaturePORT + "/api/security/message/signature";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Method           = "POST";
            request.ContentType      = "application/json;charset=utf-8";
            request.ReadWriteTimeout = 30 * 1000;
            request.Proxy            = null;

            SignatureStruct pp = new SignatureStruct();

            pp.base64Message = base64Message;
            string postStr = JsonHelper.SerializeObject(pp);

            byte[] data = Encoding.UTF8.GetBytes(postStr);
            request.ContentLength = data.Length;

            Stream myRequestStream = request.GetRequestStream();

            myRequestStream.Write(data, 0, data.Length);
            myRequestStream.Close();

            HttpWebResponse response       = (HttpWebResponse)request.GetResponse();
            StreamReader    myStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string          content        = myStreamReader.ReadToEnd();

            myStreamReader.Close();
            SignatureStructReply sigresult = JsonHelper.DeserializeJsonToObject <SignatureStructReply>(content);

            return(sigresult);
        }
コード例 #2
0
        //
        public void Signature(string strPath, string strEBDID)
        {
            string sSignFileName = "\\EBDB_" + strEBDID + ".xml";

            using (FileStream SignFs = new FileStream(strPath + sSignFileName, FileMode.Open))
            {
                StreamReader signsr  = new StreamReader(SignFs, Encoding.UTF8);
                string       xmlsign = signsr.ReadToEnd();
                signsr.Close();
                responseXML signrp     = new responseXML();
                XmlDocument xmlSignDoc = new XmlDocument();
                try
                {
                    //对文件进行签名

                    byte[] pucSignature = Encoding.UTF8.GetBytes(xmlsign);

                    string base64Message = Convert.ToBase64String(pucSignature);

                    SignatureStructReply sigresult = CalculateSignature(base64Message);
                    //生成签名文件
                    string xmlSIGNFileName = "\\EBDS_EBDB_" + strEBDID + ".xml";
                    xmlSignDoc = signrp.SignResponse(strEBDID, sigresult);
                    CommonFunc cm = new CommonFunc();
                    cm.SaveXmlWithUTF8NotBOM(xmlSignDoc, strPath + xmlSIGNFileName);
                    if (cm != null)
                    {
                        cm = null;
                    }
                }
                catch (Exception ex)
                {
                    Log.Instance.LogWrite("签名文件错误:" + ex.Message);
                }
            }
        }