Ejemplo n.º 1
0
        private void OpenScrambler()
        {
            switch (SingletonInfo.GetInstance().scramblernum)
            {
            case 0:
                //未开密码器
                break;

            case 1:
                //开启江南天安的密码器
                int nReturn = SingletonInfo.GetInstance().usb.USB_OpenDevice(ref phDeviceHandle);

                if (nReturn != 0)
                {
                    LogRecord.WriteLogFile("天安密码器打开失败!");
                    MessageBox.Show("密码器打开失败!");
                }
                else
                {
                    SingletonInfo.GetInstance().DeviceHandle = (int)phDeviceHandle;
                    LogRecord.WriteLogFile("天安密码器打开成功!");
                }
                break;

            case 2:
                //开启江南科友密码器

                //  IPAddress ip = IPAddress.Parse("127.0.0.1");
                //  IPEndPoint point = new IPEndPoint(ip, 8100);
                socketSend = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPEndPoint point = new IPEndPoint(IPAddress.Parse("192.168.4.51"), 1818);

                socketSend.Connect(point);

                //开启新的线程,不停的接收服务器发来的消息
                Thread c_thread = new Thread(Received);
                c_thread.IsBackground = true;
                c_thread.Start();

                string msg    = "\0\n12345678NC";
                byte[] buffer = new byte[2048];
                buffer = Encoding.Default.GetBytes(msg);
                socketSend.Send(buffer);
                break;

            case 5:    //调用内部CA接口  不需要打开密码器
                break;
            }
        }
Ejemplo n.º 2
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];
                    }
                }
            }
        }