예제 #1
0
        private string[] AppId    = new string[] { "CT-PT-31600", "CT-PT-31600-PC" };//长度为2

        private void find_Dog()
        {
            //加密狗的处理;
            //找狗
            for (int i = 0; i < 2; ++i)
            {
                Rtn = NT158App.NT158Find(AppId[i], out keyHandles, ref keyNum);
                if (Rtn != 0)
                {
                    //MessageBox.Show("Not Find NT158Key Error = " + Rtn);
                }
                else
                {
                    int UserPin1 = -2087732841;
                    int UserPin2 = 1648569370;
                    int UserPin3 = 1489046975;
                    int UserPin4 = 676158292;

                    Rtn = NT158App.NT158Login(keyHandles[0], UserPin1, UserPin2, UserPin3, UserPin4);
                    if (Rtn != 0)
                    {
                        // MessageBox.Show("Login Error =" + Rtn);
                    }
                    else
                    {
                        return;//找到狗
                    }
                }
            }
        }
예제 #2
0
        private void LoadKeys()
        {
            try
            {
                _selectedDogClass    = null;
                panelPrivate.Enabled = false;
                dogListTree.Nodes[0].Nodes.Clear();
                string appId = this.tbAppID.Text.Trim();
                long[] keyHandles;
                long   keyNum = 0;
                long   ret    = NT158App.NT158Find(appId, out keyHandles, ref keyNum);
                if (ret == 0)//成功
                {
                    for (int i = 0; i < keyNum; i++)
                    {
                        try
                        {
                            DogClass dogobj = new DogClass();
                            dogobj.appId     = appId;
                            dogobj.keyHandle = keyHandles[i];
                            string uid = "";
                            ret = NT158App.NT158GetUid(keyHandles[i], ref uid);
                            if (ret != 0)
                            {
                                uid = "获取失败:" + GetError(ret);
                            }
                            dogobj.uid = uid;

                            Node node = new Node("NT158_" + (i + 1));
                            node.Tag = dogobj;
                            Node appIdNode = new Node("识别码:" + dogobj.appId);
                            node.Nodes.Add(appIdNode);
                            Node uidNode = new Node("硬件序列号:" + dogobj.uid);
                            node.Nodes.Add(uidNode);
                            dogListTree.Nodes[0].Nodes.Add(node);
                        }
                        catch (Exception ex)
                        {
                            log.Error(keyHandles[i] + "加载异常:", ex);
                            MessageBox.Show(keyHandles[i] + "加载异常:" + ex.Message);
                        }
                    }
                    dogListTree.Nodes[0].Expand();
                }
                else//失败,或未找到
                {
                    MessageBox.Show("未找到任何加密狗设备,错误:" + GetError(ret));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("查找设备异常:" + ex.Message);
                log.Error("查找设备异常:", ex);
            }
        }
예제 #3
0
        public static bool Login()
        {
            try
            {
                try
                {
                    if (handle != -1)
                    {
                        NT158App.NT158Logout(handle);
                        handle = -1;
                    }
                }
                catch (Exception)
                {
                }

                long[] keyHandles;
                long   keyNum = 0;
                long   ret    = NT158App.NT158Find(appid, out keyHandles, ref keyNum);
                if (ret != 0 || keyNum <= 0)
                {
                    log.Error("加密狗加载错误:" + ret);
                    return(false);
                }
                handle = keyHandles[0];
                ret    = NT158App.NT158Login(handle, pin1, pin2, pin3, pin4);
                NT158App.NT158Led(handle, 1);
                if (ret != 0)
                {
                    log.Error("加密狗登陆错误:" + GetError(ret));
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                log.Error("加密狗加载异常:", ex);
                return(false);
            }
        }