public void GenerateSignatureFile(string strPath, string strEBDID)
        {
            if (m_UsbPwsSupport != "1")
            {
                return;
            }

            string sSignFileName = "\\EBDB_" + strEBDID + ".xml";

            using (FileStream SignFs = new FileStream(strPath + sSignFileName, FileMode.Open))
            {
                StreamReader signsr  = new StreamReader(SignFs, System.Text.Encoding.UTF8);
                string       xmlsign = signsr.ReadToEnd();
                signsr.Close();
                responseXML signrp     = new responseXML();
                XmlDocument xmlSignDoc = new XmlDocument();
                try
                {
                    //对文件进行签名
                    int    nDeviceHandle = (int)phDeviceHandle;
                    byte[] pucSignature  = Encoding.UTF8.GetBytes(xmlsign);

                    string strSignture     = "";
                    string strpucCounter   = "";
                    string strpucSignCerSn = "";
                    //string nReturn = usb.GenerateSignatureWithDevicePrivateKey(ref nDeviceHandle, pucSignature, pucSignature.Length, ref strSignture, ref strpucCounter, ref strpucSignCerSn);
                    string nReturn = usb.Platform_CalculateSingature_String(nDeviceHandle, 1, pucSignature, pucSignature.Length, ref strSignture);
                    //生成签名文件
                    string xmlSIGNFileName = "\\EBDS_EBDB_" + strEBDID + ".xml";
                    string strrefdid       = "";
                    string strResultValue  = "";
                    xmlSignDoc = signrp.SignResponse(strEBDID, strpucCounter, strpucSignCerSn, nReturn);
                    CommonFunc cm = new CommonFunc();
                    cm.SaveXmlWithUTF8NotBOM(xmlSignDoc, strPath + xmlSIGNFileName);
                    if (cm != null)
                    {
                        cm = null;
                    }
                }
                catch (Exception ex)
                {
                    Log.Instance.LogWrite("签名文件错误:" + ex.Message);
                    //xmlSignDoc = signrp.SignResponse("", "Error");
                }
                // xmlSignDoc.Save(sSourcePath + "\\EBDSign.xml");
            }
        }
Exemple #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);
                }
            }
        }