예제 #1
0
        //设置设备参数
        public bool SetConfig(out string msg)
        {
            if (ET99_API.dogHandle == System.IntPtr.Zero)
            {
                msg = "请先打开设备!";
                return(false);
            }

            byte bytUserReadOnly   = ET99_API.ET_USER_READ_ONLY;//设置为只读模式
            byte bytSoPinRetries   = byte.Parse(Properties.Resources.SOPIN重试次数);
            byte bytUserPinRetries = byte.Parse(Properties.Resources.UserPIN重试次数);
            byte bytBack           = 0;


            uint result = ET99_API.et_SetupToken(ET99_API.dogHandle, bytSoPinRetries, bytUserPinRetries, bytUserReadOnly, bytBack);

            if (result == ET99_API.ET_SUCCESS)
            {
                msg = "设备参数设置成功!";
                return(true);
            }
            else
            {
                msg = "设备参数设置失败! 错误:" + ET99_API.ShowResultText(result);
                return(false);
            }
        }
예제 #2
0
        // 查询本机是否安装加密狗
        public bool FindDog(out string msg)
        {
            msg = string.Empty;
            byte[] bytPID = new byte[8];
            int    count  = 0;

            bytPID = System.Text.Encoding.ASCII.GetBytes(Properties.Resources.PID_Default);
            uint result = ET99_API.et_FindToken(bytPID, out count);

            if (result == ET99_API.ET_SUCCESS)
            {
                msg     = "检测到加密狗--新狗";
                dogFlag = Dog_Flag.新狗;
                DoThreadSafe(() => { toolStripProgressBar1.Maximum = 16; });//新狗分为16个步骤
                return(true);
            }
            else
            {
                bytPID = System.Text.Encoding.ASCII.GetBytes(Properties.Resources.PID);
                result = ET99_API.et_FindToken(bytPID, out count);
                if (result == ET99_API.ET_SUCCESS)
                {
                    msg     = "检测到加密狗--旧狗";
                    dogFlag = Dog_Flag.旧狗;
                    DoThreadSafe(() => { toolStripProgressBar1.Maximum = 14; });//旧狗分为14个步骤
                    return(true);
                }
                msg = string.Format("系统未检测到加密狗,请检查!错误:{0}",
                                    ET99_API.ShowResultText(result));
                return(false);
            }
        }
예제 #3
0
        //修改普通用户的PIN
        public bool ModifyUserPin(out string msg)
        {
            string strOldUserPin = Properties.Resources.UserPIN_Default;

            byte[] bytOldUserPin = new byte[16];
            string strNewUserPin = Properties.Resources.UserPIN;

            byte[] bytNewUserPin = new byte[16];

            if (ET99_API.dogHandle == System.IntPtr.Zero)
            {
                msg = "请先打开设备!";
                return(false);
            }

            bytOldUserPin = System.Text.Encoding.ASCII.GetBytes(strOldUserPin);
            bytNewUserPin = System.Text.Encoding.ASCII.GetBytes(strNewUserPin);
            uint result = ET99_API.et_ChangeUserPIN(ET99_API.dogHandle, bytOldUserPin, bytNewUserPin);

            if (result == ET99_API.ET_SUCCESS)
            {
                msg = "普通用户PIN修改成功!进入普通用户状态。";
                return(true);
            }
            else
            {
                msg = "普通用户PIN修改失败! 错误:" + ET99_API.ShowResultText(result);
                return(false);
            }
        }
예제 #4
0
        //产生新的超级用户PIN(针对新狗)
        public bool GenSoPin(out string msg)
        {
            string strSeed = Properties.Resources.SOPIN种子;

            byte[] bytSeed;
            int    iSeedLen = strSeed.Length;

            if (ET99_API.dogHandle == System.IntPtr.Zero)
            {
                msg = "请先打开设备!";
                return(false);
            }

            StringBuilder strNewPIN = new StringBuilder();

            bytSeed = System.Text.Encoding.ASCII.GetBytes(strSeed);
            uint result = ET99_API.et_GenSOPIN(ET99_API.dogHandle, iSeedLen, bytSeed, strNewPIN);

            if (result == ET99_API.ET_SUCCESS)
            {
                msg = "成功产生新的超级用户PIN!请牢记 -- " + strNewPIN.ToString().Trim().Substring(0, 16);
                return(true);
            }
            else
            {
                msg = "产生新的超级用户PIN失败! 错误:" + ET99_API.ShowResultText(result);
                return(false);
            }
        }
예제 #5
0
        //重置普通用户PIN为 ffffffffffffffff
        public bool ResetUserPin(out string msg)
        {
            string strSoPIN = Properties.Resources.SOPIN;

            byte[] bytPIN = new byte[16];

            if (ET99_API.dogHandle == System.IntPtr.Zero)
            {
                msg = "请先打开设备!";
                return(false);
            }

            bytPIN = System.Text.Encoding.ASCII.GetBytes(strSoPIN);
            uint result = ET99_API.et_ResetPIN(ET99_API.dogHandle, bytPIN);

            if (result == ET99_API.ET_SUCCESS)
            {
                msg = "重置普通用户PIN为 FFFFFFFFFFFFFFFF 成功!";
                return(true);
            }
            else
            {
                msg = "重置普通用户PIN失败! 错误:" + ET99_API.ShowResultText(result);
                return(false);
            }
        }
예제 #6
0
        //产生新的PID(针对新狗)
        public bool GenPID(out string msg)
        {
            string strSeed = Properties.Resources.PID种子;

            byte[] bytSeed;
            int    iSeedLen = strSeed.Length;

            if (ET99_API.dogHandle == System.IntPtr.Zero)
            {
                msg = "请先打开设备!";
                return(false);
            }

            StringBuilder strNewPID = new StringBuilder();

            bytSeed = System.Text.Encoding.ASCII.GetBytes(strSeed);
            uint result = ET99_API.et_GenPID(ET99_API.dogHandle, iSeedLen, bytSeed, strNewPID);

            if (result == ET99_API.ET_SUCCESS)
            {
                msg = "成功写入新的PID到当前设备中! -- " + strNewPID.ToString().Trim().Substring(0, 8);
                return(true);
            }
            else
            {
                msg = "写入新的PID到当前设备失败! 错误:" + ET99_API.ShowResultText(result);
                return(false);
            }
        }
예제 #7
0
        //获取硬件SN
        public bool GetSN(out string msg)
        {
            byte[] bytSN = new byte[8];

            if (ET99_API.dogHandle == System.IntPtr.Zero)
            {
                msg = "请先打开设备!";
                return(false);
            }

            uint result = ET99_API.et_GetSN(ET99_API.dogHandle, bytSN);

            if (result == ET99_API.ET_SUCCESS)
            {
                string strSN = "";
                for (int i = 0; i < 8; ++i)
                {
                    strSN += string.Format("{0:X2}", bytSN[i]);
                }

                msg   = "获取硬件SN成功!-- " + strSN;
                dogSN = strSN;
                return(true);
            }
            else
            {
                msg = "获取硬件SN失败!错误:" + ET99_API.ShowResultText(result);
                return(false);
            }
        }
예제 #8
0
        // 校验加密狗,进入超级用户状态
        public bool VerifyDog(out string msg)
        {
            if (ET99_API.dogHandle == System.IntPtr.Zero)
            {
                msg = "请先打开设备!";
                return(false);
            }

            byte[] bytPIN = new byte[16];
            if (dogFlag == Dog_Flag.新狗)
            {
                bytPIN = System.Text.Encoding.ASCII.GetBytes(Properties.Resources.SOPIN_Default);
            }
            else
            {
                bytPIN = System.Text.Encoding.ASCII.GetBytes(Properties.Resources.SOPIN);
            }
            uint result = ET99_API.et_Verify(ET99_API.dogHandle, ET99_API.ET_VERIFY_SOPIN, bytPIN);

            if (result == ET99_API.ET_SUCCESS)
            {
                msg = "加密狗认证成功,进入超级用户状态。";
                return(true);
            }
            else
            {
                msg = string.Format("加密狗认证失败,请检查!错误:{0}",
                                    ET99_API.ShowResultText(result));
                return(false);
            }
        }
예제 #9
0
        // 打开加密狗
        public bool OpenDog(out string msg)
        {
            msg = string.Empty;
            int index = 1;//默认仅打开第一个加密狗

            byte[] bytPID = new byte[8];
            if (dogFlag == Dog_Flag.新狗)
            {
                bytPID = System.Text.Encoding.ASCII.GetBytes(Properties.Resources.PID_Default);
            }
            else
            {
                bytPID = System.Text.Encoding.ASCII.GetBytes(Properties.Resources.PID);
            }
            uint result = ET99_API.et_OpenToken(ref ET99_API.dogHandle, bytPID, index);

            if (result == ET99_API.ET_SUCCESS)//打开成功
            {
                msg = "打开加密狗成功。";
                return(true);
            }
            else
            {
                msg = string.Format("打开加密狗失败,请检查!错误:{0}",
                                    ET99_API.ShowResultText(result));
                return(false);
            }
        }
예제 #10
0
        // 关闭加密狗
        public bool CloseDog(out string msg)
        {
            msg = string.Empty;
            uint result = ET99_API.et_CloseToken(ET99_API.dogHandle);

            if (result == ET99_API.ET_SUCCESS)
            {
                ET99_API.dogHandle = System.IntPtr.Zero;
                msg = "成功关闭加密狗";
                return(true);
            }
            else
            {
                msg = string.Format("关闭加密狗失败,请检查!错误:{0}",
                                    ET99_API.ShowResultText(result));
                return(false);
            }
        }
예제 #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            int index = 1;//默认仅打开第一个加密狗

            byte[] bytPID = System.Text.Encoding.ASCII.GetBytes(Properties.Resources.PID);
            uint   result = ET99_API.et_OpenToken(ref ET99_API.dogHandle, bytPID, index);

            //------------
            byte[] bytPIN = System.Text.Encoding.ASCII.GetBytes(Properties.Resources.SOPIN);
            result = ET99_API.et_Verify(ET99_API.dogHandle, ET99_API.ET_VERIFY_SOPIN, bytPIN);
            if (result == ET99_API.ET_SUCCESS)
            {
                MessageBox.Show("加密狗认证成功,进入超级用户状态。");
            }
            else
            {
                MessageBox.Show("加密狗认证失败,请检查!错误:{0}",
                                ET99_API.ShowResultText(result));
            }
        }
예제 #12
0
        //设置8个MD5校验密匙
        public bool SetMd5Key(out string msg)
        {
            msg = string.Empty;
            if (ET99_API.dogHandle == System.IntPtr.Zero)
            {
                msg = "请先打开设备!";
                return(false);
            }

            string strMd5Key = Properties.Resources.HMAC_MD5;//需要写入的KEY

            byte[] bytShortKey = System.Text.Encoding.ASCII.GetBytes(strMd5Key);
            for (int keyid = 1; keyid <= 8; keyid++)//循环写入Md5Key
            {
                byte[] randombuffer = new byte[51];
                byte   keylen       = byte.Parse(strMd5Key.Length.ToString());
                byte   randomlen    = 51;

                byte[] sbMd5Key = new byte[32];
                byte[] sbdigest = new byte[16];

                //第一个参数是随机数,在设置密钥时没有作用
                //第二个参数是随机数长度,在设置密钥时没有作用
                //第三个参数是分配给客户的密钥
                //第四个参数是分配给客户的密钥的长度
                //第五个参数是返回的32字节的密钥,用于存到锁内
                //第六个参数在设置密钥时没有作用
                uint result = ET99_API.MD5_HMAC(randombuffer, randomlen, bytShortKey, keylen, sbMd5Key, sbdigest);
                result = ET99_API.et_SetKey(ET99_API.dogHandle, keyid, sbMd5Key);
                if (result == ET99_API.ET_SUCCESS)
                {
                    msg = "设置8个MD5校验密匙成功!";
                }
                else
                {
                    msg = string.Format("设置第{0}个MD5校验密匙失败!错误:{1}", keyid, ET99_API.ShowResultText(result));
                    return(false);
                }
            }
            return(true);
        }
예제 #13
0
        //关闭LED
        public bool CloseLED(out string msg)
        {
            if (ET99_API.dogHandle == System.IntPtr.Zero)
            {
                msg = "请先打开设备!";
                return(false);
            }

            uint result = ET99_API.et_TurnOffLED(ET99_API.dogHandle);

            if (result == ET99_API.ET_SUCCESS)
            {
                msg = "关闭LED成功!";
                return(true);
            }
            else
            {
                msg = "关闭LED失败! 错误:" + ET99_API.ShowResultText(result);
                return(false);
            }
        }