コード例 #1
0
        private DONGLE_INFO WriteData(byte[] datas)
        {
            DONGLE_INFO pDongleInfo;

            ushort pCount = 0;
            IntPtr pt     = RockeyArmHelper.EnumRockeyArm(out pCount);

            if (pCount > 1)
            {
                throw new Exception("加密锁不止一个!");
            }
            else if (pCount == 0)
            {
                throw new Exception("没有找到加密锁!");
            }
            else
            {
                pDongleInfo = (DONGLE_INFO)Marshal.PtrToStructure((IntPtr)(UInt32)pt, typeof(DONGLE_INFO));
                if (pDongleInfo.m_PID != CodyMasterPid)
                {
                    this.Init();
                }
            }

            uint hDongle = 0;

            RockeyArmHelper.OpenRockey(ref hDongle, 0);
            RockeyArmHelper.VerifyPIN(hDongle, CodyMasterPin);
            RockeyArmHelper.WriteData(hDongle, datas);

            RockeyArmHelper.CloseRockey(hDongle);
            return(pDongleInfo);
        }
コード例 #2
0
        private void Init()
        {
            byte[] codyMasterSeed = Encoding.Unicode.GetBytes("CodyMasterRockeySeed");

            ushort pCount = 0;
            var    pt     = RockeyArmHelper.EnumRockeyArm(out pCount);

            if (pCount > 1)
            {
                throw new Exception("加密锁不止一个!");
            }
            else if (pCount == 0)
            {
                throw new Exception("没有找到加密锁!");
            }
            else
            {
                DONGLE_INFO pDongleInfo = (DONGLE_INFO)Marshal.PtrToStructure((IntPtr)(UInt32)pt, typeof(DONGLE_INFO));
                if (pDongleInfo.m_PID != DefaultPid)
                {
                    throw new Exception("加密锁已被初始化!");
                }
            }

            uint hDongle = 0;

            RockeyArmHelper.OpenRockey(ref hDongle, 0);
            RockeyArmHelper.VerifyPIN(hDongle, DefaultAdminPin);
            RockeyArmHelper.GenUniqueKey(hDongle, codyMasterSeed);

            RockeyArmHelper.CloseRockey(hDongle);
        }
コード例 #3
0
        /// <summary>
        /// 读取指定Cody系统类型的加密锁
        /// </summary>
        internal ReadCustomerInfoResult ReadCustomerInfo(int codySystemType, out string error)
        {
            try
            {
                ushort pCount = 0;
                var    pt     = RockeyArmHelper.EnumRockeyArm(out pCount);

                for (int i = 0; i < pCount; i++)
                {
                    DONGLE_INFO pDongleInfo = (DONGLE_INFO)Marshal.PtrToStructure((IntPtr)((UInt32)pt + i * Marshal.SizeOf(typeof(DONGLE_INFO))), typeof(DONGLE_INFO));

                    if (pDongleInfo.m_PID == CodyMasterPid)//只读取CodyMaster初始化过的加密锁
                    {
                        uint hDongle = 0;
                        RockeyArmHelper.OpenRockey(ref hDongle, i);
                        byte[] datas      = RockeyArmHelper.ReadData(hDongle, 0, 4);
                        int    systemType = BitConverter.ToInt32(datas, 0);

                        if (systemType == codySystemType)
                        {
                            byte[] objDatas = RockeyArmHelper.ReadData(hDongle, 4);

                            error = string.Empty;
                            RockeyArmHelper.CloseRockey(hDongle);
                            return(new ReadCustomerInfoResult()
                            {
                                PDongleInfo = pDongleInfo,
                                ObjDatas = objDatas
                            });
                        }
                        else
                        {
                            RockeyArmHelper.CloseRockey(hDongle);
                        }
                    }
                }

                error = "没有找到针对此系统的加密锁!";
                return(null);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(null);
            }
        }
コード例 #4
0
        public static string ReadCustomerInfoStr(out string error)
        {
            try
            {
                ushort pCount = 0;
                var    pt     = RockeyArmHelper.EnumRockeyArm(out pCount);

                string strInfo = string.Format("共找到{0}个加密锁.", pCount);
                for (int i = 0; i < pCount; i++)
                {
                    DONGLE_INFO pDongleInfo = (DONGLE_INFO)Marshal.PtrToStructure((IntPtr)((UInt32)pt + i * Marshal.SizeOf(typeof(DONGLE_INFO))), typeof(DONGLE_INFO));

                    if (pDongleInfo.m_PID == CodyMasterPid)//只读取CodyMaster初始化过的加密锁
                    {
                        uint hDongle = 0;
                        RockeyArmHelper.OpenRockey(ref hDongle, i);
                        byte[] datas      = RockeyArmHelper.ReadData(hDongle, 0, 4);
                        int    systemType = BitConverter.ToInt32(datas, 0);

                        byte[] objDatas = RockeyArmHelper.ReadData(hDongle, 4);

                        if (systemType == (int)CodySystemTypeEnum.PQ)
                        {
                            var rockeyArm = SmartSerializeHelper.DeserializeObject <CodyPQRockeyArm>(objDatas, CodyPQRockeyArm.LoadObj);
                            strInfo += string.Format("\r\n----------第{0}个----------\r\n{1}", i + 1, rockeyArm.GetInfo());
                        }
                        else if (systemType == (int)CodySystemTypeEnum.Cert)
                        {
                            var rockeyArm = SmartSerializeHelper.DeserializeObject <CodyCertRockeyArm>(objDatas, CodyCertRockeyArm.LoadObj);
                            strInfo += string.Format("\r\n----------第{0}个----------\r\n{1}", i + 1, rockeyArm.GetInfo());
                        }

                        RockeyArmHelper.CloseRockey(hDongle);
                    }
                }

                error = string.Empty;
                return(strInfo);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(null);
            }
        }