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); }
private void LogKey(IntPtr pubKey, IntPtr priKey) { RSA_PUBLIC_KEY pubStru = IntPtrUtil.ToStru <RSA_PUBLIC_KEY>(pubKey); RSA_PRIVATE_KEY priStru = IntPtrUtil.ToStru <RSA_PRIVATE_KEY>(priKey); logger.Debug(String.Format("RSA-PRI : bit={0},modulus={1}", priStru.bits, priStru.modulus)); logger.Debug("RSA-PRI : " + Convert.ToBase64String(priStru.exponent, 0, DongleConst.RSA_KEY_LEN)); logger.Debug(String.Format("RSA-PUB : bit={0},modulus={1}", priStru.bits, priStru.modulus)); logger.Debug("RSA-PUB : " + Convert.ToBase64String(priStru.exponent, 0, DongleConst.RSA_KEY_LEN)); }