private DongleInfo[] GetDongleInfo(int count)
        {
            List <DongleInfo> keyInfo = new List <DongleInfo>();
            IntPtr            ptr     = IntPtr.Zero;

            try
            {
                int size = IntPtrUtil.SizeOf(typeof(DONGLE_INFO));
                ptr = IntPtrUtil.Create(size * (int)count);
                long __count;
                this.lastErrorCode = Dongle_Enum(ptr, out __count);

                //__count is indeed count of dongle
                for (int i = 0; i < __count; i++)
                {
                    IntPtr      __ptr   = IntPtrUtil.Create(ptr, i * size);
                    DONGLE_INFO devInfo = IntPtrUtil.ToStru <DONGLE_INFO>(__ptr);
                    keyInfo.Add(ParseDongleInfo((short)i, devInfo));
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                return(null);
            }
            finally
            {
                IntPtrUtil.Free(ref ptr);
            }
            return(keyInfo.ToArray());
        }
Пример #2
0
        private ResultArgs CreateAuthenKey(String userId, byte[] appId, byte[] adminPin)
        {
            IntPtr     pubKey = IntPtrUtil.Create(IntPtrUtil.SizeOf(typeof(RSA_PUBLIC_KEY)));
            IntPtr     priKey = IntPtrUtil.Create(IntPtrUtil.SizeOf(typeof(RSA_PRIVATE_KEY)));
            ResultArgs ret    = new ResultArgs(true);

            try
            {
                this.lastErrorCode = Dongle_RsaGenPubPriKey(this.hDongle, DongleConst.AUTHEN_KEY_DESCRIPTOR, pubKey, priKey);
                LogKey(pubKey, priKey);

                // renew appid
                this.dongleInfo[this.selectedIndex].AppId = this.Encoder.GetString(appId);

                RSA_PUBLIC_KEY pubStru = IntPtrUtil.ToStru <RSA_PUBLIC_KEY>(pubKey);
                ret.Result = new AppAuthenDongleResult()
                {
                    PubKey  = Convert.ToBase64String(pubStru.exponent, 0, DongleConst.RSA_KEY_LEN),
                    Version = this.dongleInfo[this.selectedIndex].Version,
                    AppId   = this.dongleInfo[this.selectedIndex].AppId,
                    UserId  = userId,
                    KeyPwd  = this.Encoder.GetString(adminPin),
                    KeyId   = this.dongleInfo[this.selectedIndex].KeyId
                };
            }
            finally
            {
                IntPtrUtil.Free(ref pubKey);
                IntPtrUtil.Free(ref priKey);

                // reset authen status as anonymous
                Reset();
            }
            return(ret);
        }