public string ReceiveMessageMiddle(string signature, string msgSignature, string timestamp, string nonce, string data) { XmlDocument doc = new XmlDocument(); XmlNode root; string encryptedMsg; doc.LoadXml(data); root = doc.FirstChild; encryptedMsg = root["Encrypt"].InnerText; //验证签名 if (!_verifyer.VerifySignature(signature, timestamp, nonce, _baseSettings.Token)) { throw new SignatureInValidException("签名非法"); } if (!_verifyer.VerifySignature(msgSignature, timestamp, nonce, _baseSettings.Token, encryptedMsg)) { throw new SignatureInValidException("消息签名非法"); } //解密 string message = CryptographyHelper.AESDecrypt(encryptedMsg, _baseSettings.EncodingAESKey, out string appId); if (appId != _baseSettings.AppId) { throw new AppIdInValidException("AppId验证失败"); } return(message); }
/// <summary> /// 激活绑定 /// </summary> /// <param name="code"></param> public bool Activate(string code) { ArgumentHelper.AssertNotNullOrEmpty(code, "code is null"); var args = CryptographyHelper.AESDecrypt(code).Split('_'); var tenantId = Convert.ToInt32(args[0]); var bindBatchId = Convert.ToInt32(args[1]); var bindBatch = ProviderGateway.BindBatchProvider.Get(tenantId, bindBatchId); if (bindBatch == null || bindBatch.State != BindBatchState.UnUse) { return(false); } var appUserAccount = GetById(tenantId, bindBatch.AppUserAccountId); if (appUserAccount == null || appUserAccount.State != AppUserAccountState.Inactive || appUserAccount.BeisenAccount != bindBatch.BeisenAccount) { return(false); } UpdateState(tenantId, bindBatch.AppUserAccountId, AppUserAccountState.Activated); ProviderGateway.BindBatchProvider.UpdateState(tenantId, bindBatchId, BindBatchState.Used); return(true); }
public async static ETTask LinkByAppleId(Player player, LinkInfo info, L2C_Link response) { string appleId = CryptographyHelper.AESDecrypt(info.Secret); ThirdPartyInfo appleInfo = new ThirdPartyInfo { id = appleId, }; long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(appleInfo.id, UserDataHelper.tagAppleId); if (thirdPartyUser == null) { long uid = player.uid; User user = await UserDataHelper.FindOneUser(uid); if (user == null) { response.Error = ErrorCode.ERR_LinkFailed; return; } // 綁定第三方-Apple thirdPartyUser = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId()); thirdPartyUser.uid = user.Id; thirdPartyUser.party = UserDataHelper.tagAppleId; thirdPartyUser.userId = appleInfo.id; thirdPartyUser.gender = appleInfo.gender; thirdPartyUser.location = appleInfo.location; thirdPartyUser.email = appleInfo.email; thirdPartyUser.name = appleInfo.name; thirdPartyUser.birthday = appleInfo.birthday; thirdPartyUser.createAt = now; await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser); // 取得新的第三方列表 response.LinkTypes.Clear(); response.LinkTypes.AddRange(await GetAllLinkType(user.Id)); } else { response.Error = ErrorCode.ERR_LinkIsExist; } }
private async ETVoid RunAsync(Session session, C2R_SignUp message, Action <R2C_SignUp> reply) { R2C_SignUp response = new R2C_SignUp(); try { var plain = CryptographyHelper.AESDecrypt(message.Secret); var req = BsonSerializer.Deserialize <C2R_SignUp>(plain); response.Error = await UserDataHelper.SignUp(req.Email, req.Password); if (response.Error != ErrorCode.ERR_Success) { response.ErrorCodeList = new RepeatedField <int> { ErrorCode.ERR_AccountSisnUpRepeatly }; } reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public static string Decrypt(string source) { return(CryptographyHelper.AESDecrypt(key, IV, source)); }
/// <summary> /// 使用AppleID登入 /// </summary> /// <param name="session"></param> /// <param name="info"></param> /// <param name="response"></param> /// <returns></returns> public async static ETTask AuthenticationByAppleId(Session session, AuthenticationInfo info, R2C_Authentication response) { string appleId = CryptographyHelper.AESDecrypt(info.Secret); ThirdPartyInfo appleInfo = new ThirdPartyInfo { id = appleId, }; long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(appleInfo.id, UserDataHelper.tagAppleId); User user = null; if (thirdPartyUser == null) { // 用AppleId註冊帳號 user = ComponentFactory.CreateWithId <User>(IdGenerater.GenerateId()); string salt = CryptographyHelper.GenerateRandomId(); string password = CryptographyHelper.GenerateRandomId(16); string hashPassword = CryptographyHelper.MD5Encoding(password, salt); user.salt = salt; user.hashPassword = hashPassword; user.email = appleInfo.email; user.name = user.Id.ToString(); user.gender = appleInfo.genderCode; user.location = appleInfo.locationCode; user.birthday = appleInfo.birthdayCode; user.createAt = now; user.playerCharSetting = new PlayerCharSetting(); user.playerCharSetting.CharacterId = 1L; user.playerRideTotalInfo = new RideTotalInfo(); user.language = info.Language; user.identity = (int)User.Identity.Player; user.userBagCapacity = EquipmentDataHelper.GetDefaultUserBag(); await UserDataHelper.SinUserUp(user); // 註冊第三方-AppleId thirdPartyUser = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId()); thirdPartyUser.uid = user.Id; thirdPartyUser.party = UserDataHelper.tagAppleId; thirdPartyUser.userId = appleInfo.id; thirdPartyUser.gender = appleInfo.gender; thirdPartyUser.location = appleInfo.location; thirdPartyUser.email = appleInfo.email; thirdPartyUser.name = appleInfo.name; thirdPartyUser.birthday = appleInfo.birthday; thirdPartyUser.createAt = now; await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser); // 註冊第三方-Guest thirdPartyUser = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId()); thirdPartyUser.uid = user.Id; thirdPartyUser.party = UserDataHelper.tagGuest; thirdPartyUser.userId = info.DeviceId; thirdPartyUser.name = ""; thirdPartyUser.gender = ""; thirdPartyUser.location = ""; thirdPartyUser.email = ""; thirdPartyUser.birthday = ""; thirdPartyUser.createAt = now; await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser); } else { user = await UserDataHelper.FindOneUser(thirdPartyUser.uid); } await SignInByUid(session, user, response, info.FirebaseDeviceToken, true, UserDataHelper.tagAppleId); }
public async static ETTask AuthenticationByGuest(Session session, AuthenticationInfo info, R2C_Authentication response) { string deviceUniqueIdentifier = string.Empty; try { deviceUniqueIdentifier = CryptographyHelper.AESDecrypt(info.Secret); } catch (Exception) { response.Error = ErrorCode.ERR_InvalidDeviceUniqueIdentifier; return; } if (string.IsNullOrEmpty(deviceUniqueIdentifier)) { response.Error = ErrorCode.ERR_DeviceUniqueIdentifierIsNull; return; } long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(deviceUniqueIdentifier, UserDataHelper.tagGuest); User user = null; if (thirdPartyUser == null) { user = ComponentFactory.CreateWithId <User>(IdGenerater.GenerateId()); string salt = CryptographyHelper.GenerateRandomId(); string password = CryptographyHelper.GenerateRandomId(16); string hashPassword = CryptographyHelper.MD5Encoding(password, salt); user.salt = salt; user.hashPassword = hashPassword; user.createAt = now; user.name = $"{user.Id}"; user.email = ""; user.playerCharSetting = new PlayerCharSetting(); user.playerCharSetting.CharacterId = 1L; user.playerRideTotalInfo = new RideTotalInfo(); user.language = info.Language; user.identity = (int)User.Identity.Player; user.userBagCapacity = EquipmentDataHelper.GetDefaultUserBag(); await UserDataHelper.SinUserUp(user); //註冊第三方-Guest thirdPartyUser = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId()); thirdPartyUser.uid = user.Id; thirdPartyUser.party = UserDataHelper.tagGuest; thirdPartyUser.userId = deviceUniqueIdentifier; thirdPartyUser.name = ""; thirdPartyUser.gender = ""; thirdPartyUser.location = ""; thirdPartyUser.email = ""; thirdPartyUser.birthday = ""; thirdPartyUser.createAt = now; await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser); } else { user = await UserDataHelper.FindOneUser(thirdPartyUser.uid); } await SignInByUid(session, user, response, info.FirebaseDeviceToken, true, UserDataHelper.tagGuest); }
public void Test() { var value = CryptographyHelper.AESDecrypt("DV+d4Ll+6pehQ7mEDlIq2174CkMuoBAszuSfngRh47QnM09eHcXyDgW01k16C9tfDaFsCzU1FVpnIZSptRmGknM8A2P5uutpZpitsG1O30kJ1UDlFKM0o+YVaITBMCu9aVbWMIT/e7/tR2Fu+w2NneU1I+9thmiLyKmH1S3jiPHdxbs/xJvcGYfjYGhJJ5vT7fNMphu5wrnfMRD0fUSyXg=="); var userCookie = SerializeHelper.Deserialize <UserCookie>(value); }