Exemple #1
0
        public void InitStreamTable()
        {
            //设置需要发送的表
            if (formDailyBroadcast != null)
            {
                EbmStream.Daily_Broadcast_Table = formDailyBroadcast.GetDailyBroadcastTable(ref Daily_Broadcast_Table) ? Daily_Broadcast_Table : null;
            }
            if (formIndex != null)
            {
                formIndex.GetEBIndexTable(ref EB_Index_Table);
                EbmStream.EB_Index_Table = EB_Index_Table;
            }
            //if (formConfigure != null)
            //{
            //    EbmStream.EB_Configure_Table = formConfigure.GetConfigureTable(ref EB_Configure_Table) ? EB_Configure_Table : null;
            //}
            if (formContent != null)
            {
                EbmStream.list_EB_Content_Table = formContent.GetlistContentTable(ref list_EB_Content_Table) ? list_EB_Content_Table : null;
            }
            if (formCertAuth != null)
            {
                EbmStream.EB_CertAuth_Table = formCertAuth.GetCertAuthTable(ref EB_CertAuth_Table) ? EB_CertAuth_Table : null;
            }

            if (SingletonInfo.GetInstance().IsUseCAInfo)
            {
                EbmStream.SignatureCallbackRef = new EBMStream.SignatureCallBackDelegateRef(calcel.SignatureFunc);//每次在 Initialization()之前调用
            }
            else
            {
                EbmStream.SignatureCallbackRef = null;
            }
            EbmStream.Initialization();
            isInitStream = true;
            if (thread != null)
            {
                thread.Abort();
            }
            thread = new Thread(UpdateDataText);
            thread.IsBackground = true;
            thread.Start();
        }
Exemple #2
0
        private void CloseScrambler()
        {
            switch (SingletonInfo.GetInstance().scramblernum)
            {
            case 0:
                //未开密码器 可直接关闭
                break;

            case 1:
                int nDeviceHandle = (int)phDeviceHandle;
                int nReturn       = SingletonInfo.GetInstance().usb.USB_CloseDevice(ref nDeviceHandle);
                SingletonInfo.GetInstance().OpenScramblerReturn = 2;
                //关闭江南天安的密码器
                break;

            case 2:
                //关闭江南科友密码器
                break;
            }
        }
Exemple #3
0
        private List <EBIndex> GetSendEBMIndex()
        {
            if (EBIndex_List.Count == 0)
            {
                return(null);
            }
            List <EBIndex> list = new List <EBIndex>();

            foreach (var index in EBIndex_List)
            {
                if (index.SendState)
                {
                    index.EBIndex.ProtocolGX = SingletonInfo.GetInstance().IsProtocolGX;
                    list.Add(index.EBIndex);
                    if (!index.DesFlag)
                    {
                        list[list.Count - 1].DetlChlDescriptor = null;
                    }
                }
            }
            return(list);
        }
Exemple #4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (Convert.ToInt32(cmbCAname.SelectedValue) == 5)
                {
                    if (chbplatformsignature.Checked == false && chbCAsignature.Checked == false && chbplatformsignatureNew.Checked == false)
                    {
                        MessageBox.Show("请勾选平台证书签名/CA签名!");
                        return;
                    }

                    if (chbplatformsignatureNew.Checked)
                    {
                        SingletonInfo.GetInstance().InlayCAType = 2;
                    }
                    if (chbplatformsignature.Checked)
                    {
                        SingletonInfo.GetInstance().InlayCAType = 1;
                    }
                    if (chbCAsignature.Checked)
                    {
                        SingletonInfo.GetInstance().InlayCAType = 0;
                    }
                }

                if (chbCheckSignature.Checked)
                {
                    SingletonInfo.GetInstance().ischecksignature = true;
                }
                else
                {
                    SingletonInfo.GetInstance().ischecksignature = false;
                }

                if (SingletonInfo.GetInstance().OpenScramblerReturn != 0)
                {
                    SingletonInfo.GetInstance().scramblernum = Convert.ToInt32(cmbCAname.SelectedValue);

                    if (CASetEvent != null)
                    {
                        CASetEvent();//引发事件
                    }
                }

                SingletonInfo.GetInstance().IsUseCAInfo = chbUseSignature.Checked; //是否启用签名

                cf["IsCAInfoSet"] = "1";
                cf["IsUseCA"]     = chbUseSignature.Checked ? "1" : "0";
                if (!chbUseSignature.Checked)
                {
                    //初始化
                }

                cf["CAtype"] = Convert.ToInt32(cmbCAname.SelectedValue).ToString();
                if (Convert.ToInt32(cmbCAname.SelectedValue) == 5)
                {
                    if (chbplatformsignatureNew.Checked)
                    {
                        cf["InlayCA"] = "2";
                    }
                    if (chbplatformsignature.Checked)//平台签名
                    {
                        cf["InlayCA"] = "1";
                    }
                    if (chbCAsignature.Checked)
                    {
                        cf["InlayCA"] = "0";
                    }
                }

                cf["CheckSignature"] = chbCheckSignature.Checked ? "1" : "0";
                cf["IsCASet"]        = "1";



                if (checkBox1.Checked)
                {
                    SingletonInfo.GetInstance().manuAddCert_sn = true;
                    SingletonInfo.GetInstance().CurrentCert_SN = txtCert_sn.Text;

                    EBCert tmp = new EBCert();
                    tmp.Cert_sn = SingletonInfo.GetInstance().CurrentCert_SN;
                    switch (tmp.Cert_sn)

                    {
                    case "000000000007":
                        tmp.PriKey = "57C6140969FE97A75C3C7AFBFDCDFA3951147BF6EE7FC391AABAA8721FEA9AB0";
                        tmp.PubKey = "B086AA7AFBACBD9C81A7717BD4C493291EA0EDACD1ADEF1A4AB05BD14BBF1F4A78A195559C02D0195C1675BC6CF817CCB32A675BCAE12C52C672840C377C50C2";
                        break;

                    case "000000000008":
                        tmp.PriKey = "E884E9313BACCC26F393B21FCF992E73A6FE359D86149EB573EF47A7FF82B0E3";
                        tmp.PubKey = "4DE92C85B9104476298D61D8A8BE570D8A00D60F30BD2254D5DFEEC7A873A5DB63FD5936E4EB35F6AA8EECBB85346ADEA08F406BFD3D2C11548431D57A6FDF6F";
                        break;

                    case "000000000009":
                        tmp.PriKey = "1208B7BBACB1265EF100DBB2C0F9E55820EA4FAEEECB54B00F3EBE665398CE95";
                        tmp.PubKey = "4466BFA3C0CF3342F4970FCBEA10A95A439B8D9DB4AC90BB123FBC2E500418DA7BB039EB63FA27C8A91C3C51CF4FCE109C501DDE9456615A13E7C159FBFF8B73";
                        break;
                    }


                    int index = SingletonInfo.GetInstance().InlayCA.AddEBCert(tmp);
                    SingletonInfo.GetInstance().DicCert.Add(tmp.Cert_sn, index);
                }

                Close();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #5
0
        public void SignatureFunc(byte[] pdatabuf, int datalen, ref int random, ref byte[] signature)
        {
            byte[] strSignture  = new byte[100];
            byte[] pucSignature = pdatabuf;

            if (!SingletonInfo.GetInstance().manuAddCert_sn)
            {
                switch (SingletonInfo.GetInstance().scramblernum)
                {
                case 1:

                    int nDeviceHandle = SingletonInfo.GetInstance().DeviceHandle;


                    string eturn = SingletonInfo.GetInstance().usb.Platform_CalculateSingature_String(nDeviceHandle, 1, pucSignature, pucSignature.Length, ref strSignture);
                    strSignture.CopyTo(signature, 0);
                    if (eturn == "NetError")
                    {
                        MyEvent();     //引发事件  提示主界面
                    }
                    break;

                case 5:

                    //switch (SingletonInfo.GetInstance().InlayCAType)
                    //{
                    //    case 0:
                    //        SingletonInfo.GetInstance().InlayCA.EbMsgCASign(pdatabuf, datalen, ref random, ref signature);

                    //        break;

                    //    case 1:

                    //        SingletonInfo.GetInstance().InlayCA.EbMsgPLSign(pdatabuf, datalen, ref random, ref signature);
                    //        break;

                    //    case 2:
                    //        SingletonInfo.GetInstance().InlayCA.EbMsgSign(pdatabuf, datalen,ref random, ref signature,2);
                    //        break;
                    //}

                    SingletonInfo.GetInstance().InlayCA.EbMsgSign(pdatabuf, datalen, ref random, ref signature, SingletonInfo.GetInstance().InlayCAType);
                    break;
                }
            }
            else
            {
                int certindex = SingletonInfo.GetInstance().DicCert[SingletonInfo.GetInstance().CurrentCert_SN];


                SingletonInfo.GetInstance().InlayCA.EbMsgSign(pdatabuf, datalen, ref random, ref signature, certindex);
            }


            string strData = null;

            for (int i = 0; i < pucSignature.Length; i++)
            {
                strData += " " + pucSignature[i].ToString("X2");
            }
            LogRecord.WriteLogFile("原文:" + strData);
            string strData2 = null;

            for (int i = 0; i < signature.Length; i++)
            {
                strData2 += " " + signature[i].ToString("X2");
            }
            LogRecord.WriteLogFile("签名数据:" + strData2);

            if (SingletonInfo.GetInstance().ischecksignature)
            {
                DateTime dt = DateTime.UtcNow;
                string   tt = UtcHelper.ConvertDateTimeInt(dt).ToString();

                byte[] byteArray = System.Text.Encoding.Default.GetBytes(tt);
                if (byteArray.Length > 0 && byteArray.Length < 64)
                {
                    for (int i = 0; i < byteArray.Length; i++)
                    {
                        signature[10 + i] = byteArray[i];
                    }
                }
            }
        }