public String getToken() { // 產生一個 5 個字元的亂碼字串 var pwd = new Password(5).IncludeNumeric(); var Captcha = pwd.Next(); // 封裝字符和過期時間 CaptchaModel captchaModel = new CaptchaModel(); captchaModel.Code = Captcha; //設定過期時間為一分鐘 captchaModel.Exp = DateTime.Now.AddMinutes(1); //轉換json字串 string jsonString = JsonSerializer.Serialize(captchaModel); System.Console.WriteLine(jsonString); //AES加密 string token = StringEncrypt.aesEncryptBase64(jsonString, CryptoKey); //取代特殊符號回傳 return(base64url_encode(token)); }
/// <summary> /// 用户登录 /// </summary> /// <param name="mobile"></param> /// <param name="password"></param> /// <param name="userType"></param> /// <returns></returns> private ResponseUserDTO CheckLogin(RequestUserLoginDTO dto) { ResponseUserDTO userModel = null; if (!string.IsNullOrEmpty(dto.OpenID)) { userModel = GetUserInfoByOpenID(dto.OpenID); return(userModel); } else { //获取手机号码 userModel = GetUserInfoByMobile(dto.Mobile, dto.UserType); //用户存在,状态正常,未被删除 if (userModel != null) { string shapassword = StringEncrypt.EncryptWithSHA(dto.Password.Trim()); string md5password = StringEncrypt.EncryptWithMD5(dto.Password.Trim()); //登录密码正确 if (userModel.Password == shapassword || userModel.Password == md5password) { return(userModel); } } } return(null); }
protected override async Task <Example> BuildExample(Guid challengeId) { var question = new Question { InputValues = new List <Value> { new Value { Name = "number", Data = $"{1}" }, new Value { Name = "hash", Data = $"{StringEncrypt.Encrypt($"{1}","seppeisthebest")}" }, } }; return(new Example { Question = question, Answer = await BuildAnswer(question, challengeId) }); }
/// <summary> /// 驗證token是否正確 /// </summary> /// <param name="token"></param> /// <returns>回傳Model</returns> public CaptchaModel vaildate([FromHeader] String token) { //判斷是否輸入 if (String.IsNullOrEmpty(token)) { return(null); } //還原 token = base64url_decode(token); //AES解密 var jsonString = StringEncrypt.aesDecryptBase64(token, CryptoKey); //轉換物件 var captchaModel = JsonSerializer.Deserialize <CaptchaModel>(jsonString); //取得資料 var Captcha = captchaModel.Code; var Exp = captchaModel.Exp; //判斷時間是否過期 if (DateTime.Now > Exp) { return(null); } return(captchaModel); }
public ApiResult UserFindPwdPre([FromBody] UserFindPwdPreDto request) { #region 短信验证码和手机号相关验证 ApiResult msgResult; var userService = new BLL.User.Implements.UserService(); var userInfo = userService.GetUserInfoByMobile(request.Mobile, request.UserType); if (userInfo == null) { msgResult = new ApiResult() { Status = EnumApiStatus.BizError, Msg = "对不起此手机号未注册" }; return(msgResult); } if (!serviceMsgLog.CheckVerifyCode(request.Mobile, request.MsgType.ToString(), request.MsgVerifyCode)) { msgResult = new ApiResult() { Status = EnumApiStatus.BizError, Msg = "对不起此短信验证码不存在或已经过期" }; return(msgResult); } string uid = StringEncrypt.Encrypt(userInfo.UserID); uid = HttpUtility.UrlEncode(uid); msgResult = new ApiResult { Status = 0, Msg = "", Data = uid }; return(msgResult); #endregion }
public void Load() { configDatas = new TestIOCsvConfigDatas(); dicData.Clear(); listData.Clear(); StreamReader streamReader = null; if (File.Exists(DataPath())) { streamReader = File.OpenText(DataPath()); } else { Debug.LogError(GetType() + "/Load() load config eroor! path:" + DataPath()); return; } string str = streamReader.ReadToEnd(); streamReader.Close(); streamReader.Dispose(); string textData = StringEncrypt.DecryptDES(str); m_datas = CSVConverter.SerializeCSVData(textData); Serialization(); }
public ResponseLoginDTO Login(RequestLoginDTO dto) { using (var db = new DBEntities()) { var password = StringEncrypt.EncryptWithMD5(dto.Password); var model = db.Users.Where(t => t.Password == password && t.UserID == dto.UserID && !t.IsDeleted).FirstOrDefault(); if (model != null) { model.UserToken = Guid.NewGuid().ToString("N"); model.LastTime = DateTime.Now; LoginLog log = new LoginLog() { LogID = Guid.NewGuid().ToString("N"), LoginAccount = model.UserID, LoginName = model.UserName, LoginTime = model.LastTime.Value.ToString("yyyy-MM-dd HH:mm:ss") }; db.LoginLogs.Add(log); db.SaveChanges(); return(new ResponseLoginDTO() { UserToken = model.UserToken }); } return(null); } }
public void SDK_NSK_CLIENT_dev_modify_osdTest() { string strGuid = "63-00F628C58502-1528"; string Temp_strValue = StringEncrypt.Base64Encode("123"); SDK_SKNVideo.SDK_NSK_CLIENT_dev_modify_osd(strGuid, 10, Temp_strValue); CommonMethod.Common.Delay_Millisecond(5000); Assert.Fail(); }
public bool LoadGame(int saveSlot) { if (saveSlot >= 0) { string saveFilename = this.GetSaveFilename(saveSlot); if (!string.IsNullOrEmpty(saveFilename) && File.Exists(Application.persistentDataPath + saveFilename)) { try { string toDecrypt = string.Empty; string json = string.Empty; BinaryFormatter binaryFormatter = new BinaryFormatter(); FileStream fileStream = File.Open(Application.persistentDataPath + saveFilename, FileMode.Open); if (this.gameConfig.useSaveEncryption) { toDecrypt = (string)binaryFormatter.Deserialize(fileStream); } else { json = (string)binaryFormatter.Deserialize(fileStream); } fileStream.Close(); if (this.gameConfig.useSaveEncryption) { json = StringEncrypt.DecryptData(toDecrypt); } Logger.LogFine("[API] - Loading Game:" + json); SaveGameData saveGameData = JsonUtility.FromJson <SaveGameData>(json); global::PlayerData instance = saveGameData.playerData; SceneData instance2 = saveGameData.sceneData; ModHooks.Instance.OnAfterSaveGameLoad(saveGameData); global::PlayerData.instance = instance; this.playerData = instance; SceneData.instance = instance2; this.sceneData = instance2; this.profileID = saveSlot; this.inputHandler.RefreshPlayerData(); ModHooks.Instance.OnSavegameLoad(saveSlot); return(true); } catch (Exception ex) { Debug.LogFormat("Error loading save file for slot {0}: {1}", new object[] { saveSlot, ex }); return(false); } } Debug.Log("Save file not found for slot " + saveSlot); return(false); } Debug.LogError("Save game slot not valid: " + saveSlot); return(false); }
public void TestMethod1() { Startup(); UsersService service = new UsersService(); var obj = service.GetObject(new UsersInfo() { UserAccount = "jack", Password = StringEncrypt.EncryptWithMD5("123456") }); var m = service.GetObject(1); }
private void button6_Click(object sender, EventArgs e) { try { textBox10.Text = StringEncrypt.aesDecryptBase64(textBox8.Text, textBox9.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public SaveStats GetSaveStatsForSlot(int saveSlot) { if (saveSlot > 0) { string saveFilename = this.GetSaveFilename(saveSlot); if (!string.IsNullOrEmpty(saveFilename) && File.Exists(Application.persistentDataPath + saveFilename)) { try { string toDecrypt = string.Empty; string json = string.Empty; BinaryFormatter binaryFormatter = new BinaryFormatter(); FileStream fileStream = File.Open(Application.persistentDataPath + saveFilename, FileMode.Open); if (this.gameConfig.useSaveEncryption) { toDecrypt = (string)binaryFormatter.Deserialize(fileStream); } else { json = (string)binaryFormatter.Deserialize(fileStream); } fileStream.Close(); if (this.gameConfig.useSaveEncryption) { json = StringEncrypt.DecryptData(toDecrypt); } SaveGameData saveGameData = JsonUtility.FromJson <SaveGameData>(json); global::PlayerData playerData = saveGameData.playerData; SaveStats stats = new SaveStats(playerData.maxHealthBase, playerData.geo, playerData.mapZone, playerData.playTime, playerData.MPReserveMax, playerData.permadeathMode, playerData.completionPercentage, playerData.unlockedCompletionRate) { Name = saveGameData.Name, LoadedMods = saveGameData.LoadedMods }; return(stats); } catch (Exception ex) { Debug.LogError(string.Concat(new object[] { "Error while loading save file for slot ", saveSlot, " Exception: ", ex })); return(null); } } return(null); } Debug.LogError("Save game slot not valid: " + saveSlot); return(null); }
public bool InitConfig() { bool success = true; string fileName = ""; lock (this.RuntimeData.Mutex) { try { int group = 0; this.RuntimeData.SDKGameID = StringEncrypt.Decrypt(GameManager.PlatConfigMgr.GetGameConfigItemStr("gvoice_app_id", ""), "eabcix675u49,/", "3&3i4x4^+-0"); this.RuntimeData.SDKKey = StringEncrypt.Decrypt(GameManager.PlatConfigMgr.GetGameConfigItemStr("gvoice_app_key", ""), "eabcix675u49,/", "3&3i4x4^+-0"); this.RuntimeData.VoiceMessage = GameManager.systemParamsList.GetParamValueIntArrayByName("VoiceMessage", ','); this.RuntimeData.VoicePowerNum = GameManager.systemParamsList.GetParamValueIntArrayByName("VoicePowerNum", ','); this.RuntimeData.MapCode2GVoiceTypeDict.Clear(); this.RuntimeData.MapCode2GVoiceGroupDict.Clear(); string str = GameManager.systemParamsList.GetParamValueByName("ZhanMengVoice"); if (!string.IsNullOrEmpty(str)) { List <List <int> > ls = ConfigHelper.ParserIntArrayList(str, false, '|', ','); foreach (List <int> list in ls) { group++; foreach (int mapCode in list) { this.RuntimeData.MapCode2GVoiceTypeDict[mapCode] = 1; this.RuntimeData.MapCode2GVoiceGroupDict[mapCode] = group; } } } str = GameManager.systemParamsList.GetParamValueByName("JunTuanVoice"); if (!string.IsNullOrEmpty(str)) { List <List <int> > ls = ConfigHelper.ParserIntArrayList(str, false, '|', ','); foreach (List <int> list in ls) { group++; foreach (int mapCode in list) { this.RuntimeData.MapCode2GVoiceTypeDict[mapCode] = 2; this.RuntimeData.MapCode2GVoiceGroupDict[mapCode] = group; } } } } catch (Exception ex) { success = false; LogManager.WriteLog(LogTypes.Fatal, string.Format("加载xml配置文件:{0}, 失败。", fileName), ex, true); } } return(success); }
public static Account Login(Urls urls, string accessToken) { var client = new RestClient(urls.UserUrl); var request = new RestRequest("Login"); request.AddParameter("Authorization", accessToken, ParameterType.HttpHeader); var response = client.Post(request); var content = StringEncrypt.Decrypt(response.Content, userKey); var definition = new { Code = "", Msg = "", Account = new SlitherEvo.Account() }; return(JsonConvert.DeserializeAnonymousType(content, definition).Account); }
public void TestMd5Success() { //Arrange string text = "1234"; string expected = "81dc9bdb52d04dc20036dbd8313ed055"; //Act string result = StringEncrypt.Md5Encrypt(text); //Assert Assert.AreEqual(expected, result); }
public void TestDesException() { //Arrange string key = "12345"; string iv = "87654"; string text = "f66U/RqLiA2NVFTdjfMMQA=="; //Act string result = StringEncrypt.DesDecryptBase64(text, key, iv); //no assert }
public bool AddAccount(RequestUserInfoDTO dto, out string reason) { reason = ""; using (var db = new DBEntities()) { User ua = dto.Map <RequestUserInfoDTO, User>(); ua.ID = Guid.NewGuid().ToString("N"); ua.Password = StringEncrypt.EncryptWithMD5(dto.Password); db.Users.Add(ua); return(db.SaveChanges() > 0); } }
private static string DataFileRead() { string saves = ""; using (FileStream fs = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read)) { using (BinaryReader r = new BinaryReader(fs)) { saves = r.ReadString(); } } saves = StringEncrypt.aesDecryptBase64(saves, FILE_KEY); return(saves); }
/// <summary> /// CSV数据加密 /// </summary> /// <param name="textPath">Text路径</param> /// <param name="textAsset">Text数据</param> private static void CsvEncrypt(string textPath, string textAsset) { string data = StringEncrypt.EncryptDES(textAsset); if (File.Exists(textPath)) { File.Delete(textPath); } StreamWriter sr = File.CreateText(textPath); sr.WriteLine(data); sr.Close(); }
public void TestDesDecrypt() { //Arrange string key = "12345678"; string iv = "87654321"; string text = "f66U/RqLiA2NVFTdjfMMQA=="; string expected = "hello world"; //Act string result = StringEncrypt.DesDecryptBase64(text, key, iv); //Assert Assert.AreEqual(expected, result); }
private void button_protect_Click(object sender, EventArgs e) { try { Console.Clear(); Greeting greeting = new Greeting(); Console.ForegroundColor = ConsoleColor.DarkGreen; ModuleWriterOptions Options = null; if (checkBox_stringEncrypt.Checked) { Console.Write("String obfuscating... "); StringEncrypt stringEncrypt = new StringEncrypt(ref moduleDef); Console.Write("OK!\n"); } if (checkBox_Renamer.Checked && renamerForm.AssemblyName != String.Empty) { Console.Write("Renaming assembly..."); Renamer renamer = new Renamer(ref moduleDef, renamerForm.AssemblyName, renamerForm.ModuleName); Console.Write("OK!\n"); } if (checkBox_AntiDe4dot.Checked) { Console.Write("AntiDe4dot init..."); Anti_De4dot antiDe4dot = new Anti_De4dot(); Options = antiDe4dot.AntiDe4dotInit(ref moduleDef); Console.Write("OK!\n"); } if (checkbox_antiILSpy.Checked) { MethodDef[] userMethods = methodsListForm.listBox_selectedMethods.Items.Cast <MethodDef>().ToArray(); AntiILSpy antiIlSpy = new AntiILSpy(ref moduleDef, userMethods); } var writerOptions = new dnlib.DotNet.Writer.ModuleWriterOptions(moduleDef); writerOptions.Logger = DummyLogger.NoThrowInstance; Console.Write("Saving assembly..."); moduleDef.Write(Path.GetDirectoryName(textBox_filePath.Text) + "\\" + Path.GetFileNameWithoutExtension(textBox_filePath.Text) + "_MADNESS" + Path.GetExtension(textBox_filePath.Text), writerOptions); Console.Write("OK!\n"); methodsListForm.Close(); } catch (System.IO.IOException exception) { MessageBox.Show(exception.Message); } }
public static Account CreateAccount(Urls urls, string accessToken) { var client = new RestClient(urls.UserUrl); var request = new RestRequest("Login"); request.AddParameter("Authorization", accessToken, ParameterType.HttpHeader); var input = StringEncrypt.Encrypt(JsonConvert.SerializeObject(new { Language = "Taiwan" }), userKey); request.AddParameter("application/json", input, ParameterType.RequestBody); var response = client.Post(request); var content = StringEncrypt.Decrypt(response.Content, userKey); var definition = new { Code = "", Msg = "", Account = new SlitherEvo.Account() }; return(JsonConvert.DeserializeAnonymousType(content, definition).Account); }
public void HttpGetTest() { StringBuilder sbExecSQL = new StringBuilder(); sbExecSQL.Append("SELECT * FROM 报警基本信息 ORDER BY 主机编号 "); //string strUrl = "https://lr.mmall.com/SK3000WebServiceCore/api/DataBase/GetData?ExecSQL=" + StringEncrypt.Encrypt(sbExecSQL.ToString()); string Temp_str = StringEncrypt.Base64Encode(sbExecSQL.ToString()).Replace("+", "%2B"); string strUrl = "http://localhost:4827/SK3000WebServiceCore/api/DataBase/GetData?ExecSQL=" + Temp_str; DateTime tim = DateTime.Now; string strResult = Common_Web.HttpGet(strUrl, ""); DateTime tim1 = DateTime.Now; TimeSpan ts = tim1 - tim; Assert.AreEqual(strResult.Length, 100); }
private static Urls QueryIP(string agentServerIP, string clientVer, string loginType) { var input = JsonConvert.SerializeObject(new { ClientVersion = clientVer, LoginType = loginType }); input = StringEncrypt.Encrypt(input, userKey); Uri agentServer = new Uri(agentServerIP); var client = new RestClient(agentServer); var request = new RestRequest("QueryIP"); request.AddParameter("Json", input, ParameterType.QueryString); var response = client.Post(request); var content = response.Content; return(JsonConvert.DeserializeObject <Urls>(content)); }
/// <summary> /// 找回密码 /// </summary> /// <param name="userID"></param> /// <param name="userPwd"></param> /// <returns></returns> public bool ResetPassword(string userID, string userPwd) { if (base.Update(userID, i => new Entity.User { Password = StringEncrypt.EncryptWithMD5(userPwd) })) { //采用缓存淘汰策略 var cacheKey_User = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(StringCacheKeyType.User, userID); cacheKey_User.RemoveCache(); return(true); } else { return(false); } }
private static string Authentication(Urls url, string devicedId) { var client = new RestClient(url.UserUrl); var request = new RestRequest("Authentication"); var input = JsonConvert.SerializeObject(new { DeviceID = devicedId, SecretOpenID = "" }); input = StringEncrypt.Encrypt(input, userKey); request.AddParameter("application/json", input, ParameterType.RequestBody); var response = client.Post(request); var content = StringEncrypt.Decrypt(response.Content, userKey); var definition = new { Code = "", Msg = "", AccessToken = "" }; var result = JsonConvert.DeserializeAnonymousType(content, definition); return(result.AccessToken); }
public bool ResetPassword(RequestChangePasswordDTO dto) { using (var db = new DBEntities()) { var password = StringEncrypt.EncryptWithMD5(dto.NewPassword); var model = db.Users.Where(t => t.ID == dto.ID && !t.IsDeleted).FirstOrDefault(); if (model != null) { model.Password = password; var ret = db.SaveChanges() > 0; return(ret); } return(false); } }
public ApiResult UserFindPwdNext([FromBody] UserFindPwdNextDto request) { #region 相关验证 ApiResult msgResult; if (string.IsNullOrEmpty(request.Id)) { msgResult = new ApiResult() { Status = EnumApiStatus.BizError, Msg = "对不起此手机号未注册" }; return(msgResult); } else { userService = new BLL.User.Implements.UserService(); request.Id = StringEncrypt.Decrypt(request.Id); var userInfo = userService.GetUserInfoByUserId(request.Id); if (userInfo != null) { if (userService.ResetPassword(userInfo.UserID, request.Password)) { msgResult = new ApiResult { Status = EnumApiStatus.BizOK, Msg = "密码设置成功" }; return(msgResult); } else { msgResult = new ApiResult { Status = EnumApiStatus.BizError, Msg = "密码设置失败" }; return(msgResult); } } else { msgResult = new ApiResult { Status = EnumApiStatus.BizError, Msg = "对不起此用户不存在" }; return(msgResult); } } return(msgResult); #endregion }
protected override Task <Answer> BuildAnswer(Question question, Guid challengeId) { var hash = question.InputValues.Single(e => e.Name.Equals("hash")).Data; return(Task.FromResult(new Answer { ChallengeId = challengeId, Values = new List <Value> { new Value { Name = "number", Data = $"{StringEncrypt.Decrypt(hash,"seppeisthebest")}" } } })); }
/// <summary> /// 修改密码信息 /// </summary> /// <param name="userModel"></param> public ApiResult ChangePassword(RequestUserChangePasswordDTO passwordModel) { try { using (DBEntities db = new DBEntities()) { if (passwordModel.NewPassword != passwordModel.ConfirmPassword.Trim()) { return(EnumApiStatus.BizChangePasswordConfirmPasswordError.ToApiResultForApiStatus()); } if (passwordModel.NewPassword == passwordModel.OldPassword) { return(EnumApiStatus.BizChangePasswordNewPasswordEqualOld.ToApiResultForApiStatus()); } string oldMD5 = StringEncrypt.EncryptWithMD5(passwordModel.OldPassword); string oldSHA = StringEncrypt.EncryptWithSHA(passwordModel.OldPassword); var user = db.Users.Where(t => t.UserID == passwordModel.UserID && (t.Password == oldMD5 || t.Password == oldSHA)).FirstOrDefault(); if (user == null) { return(EnumApiStatus.BizChangePasswordOldPasswordError.ToApiResultForApiStatus()); } user.Password = StringEncrypt.EncryptWithMD5(passwordModel.NewPassword); if (db.SaveChanges() > 0) { var GetUserIDByMobile_CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(StringCacheKeyType.User, passwordModel.UserID); GetUserIDByMobile_CacheKey.RemoveCache(); return(EnumApiStatus.BizOK.ToApiResultForApiStatus("密码修改成功")); } else { return(EnumApiStatus.BizChangePasswordOldPasswordError.ToApiResultForApiStatus()); } } } catch (Exception ex) { LogHelper.WriteError(ex); return(EnumApiStatus.BizError.ToApiResultForApiStatus("修改密码失败")); } }