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); }
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); }