public static void SetString(string key, string value, string password) { DESEncryption dESEncryption = new DESEncryption(); string str = SecurePlayerPrefs.GenerateMD5(key); PlayerPrefs.SetString(str, dESEncryption.Encrypt(value, password)); }
private static bool LoadData() { var valid = false; var data = PlayerPrefs.GetString("data", ""); if (data != "") { var success = DESEncryption.TryDecrypt(data, out var original); if (success) { GAME_DATA = JsonUtility.FromJson <GameData>(original); GAME_DATA.LoadData(); valid = true; } else { GAME_DATA = new GameData(); } } else { GAME_DATA = new GameData(); } return(valid); }
public static void SetString(string key, string value, string password) { var desEncryption = new DESEncryption(); string hashedKey = GenerateMD5(key); string encryptedValue = desEncryption.Encrypt(value, password); PlayerPrefs.SetString(hashedKey, encryptedValue); }
private void _LoadBinary() { if (File.Exists(Application.persistentDataPath + "/" + this.localKey + ".dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/" + this.localKey + ".dat", FileMode.Open); string str_json = bf.Deserialize(file) as string; var desEncryption = new DESEncryption(); string decryptedValue; if (desEncryption.TryDecrypt(str_json, enc_password, out decryptedValue)) { json = new JSONObject(decryptedValue); // check version and add any new fields, also add them in resetdata } else { resetData(); SavePlayerData(); } file.Close(); } else { resetData(); SavePlayerData(); } }
public void SetString(string key, string value, string password) { var desEncryption = new DESEncryption (); string hashedKey = GenerateMD5 (key); string encryptedValue = desEncryption.Encrypt (value, password); PlayerPrefs.SetString (hashedKey, encryptedValue); }
public static void SetString(string key, string value, string password) { DESEncryption dESEncryption = new DESEncryption(); string text = GenerateMD5(key); string text2 = dESEncryption.Encrypt(value, password); PlayerPrefs.SetString(text, text2); }
public EncryptionScenarioViewModel( DESEncryption desEncryption, AESEncryption aesEncryption, TrueCrypt trueCrypt) : base() { DisplayName = "Encryption"; Scenarios.Add(desEncryption); Scenarios.Add(aesEncryption); Scenarios.Add(trueCrypt); }
public byte[] decrypt(byte[] data, byte[] Vetor, byte[] hmac) { byte[] buffer = new byte[0]; Array.Resize(ref buffer, data.Length - 10); Array.Copy(data, 0, buffer, 0, data.Length - 10); byte[] packet = DESEncryption.DecryptData(buffer, Vetor, hmac); Array.Resize(ref buffer, packet.Length - 16); Array.Copy(packet, 16, buffer, 0, buffer.Length); return(buffer); }
private static bool SaveConfig(ProjectBuildData data, bool encrypt) { try { string path = Application.streamingAssetsPath + "/" + GameHelper.GetBuildTargetName(data.Target) + "/"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string fileName = path + GlobalConst.Res.AppConfigFileName; string text = LitJson.JsonMapper.ToJson(data.Options); if (File.Exists(fileName)) { File.Delete(fileName); } if (encrypt) { text = DESEncryption.Encrypt(text, GlobalConst.Res.EncryptPassword); } File.WriteAllText(fileName, text); fileName = path + GlobalConst.Res.GameConfigFileName; if (data.Games.Count > 0) { var ids = new List <int>(); foreach (var game in data.Games) { ids.Add(game.Key); } var games = GameWindow.ScanGames(data.Target, ids); foreach (var game in data.Games) { var item = games.Find((config) => config.ID == game.Key); item.Packed = game.Value; } text = LitJson.JsonMapper.ToJson(games); } if (File.Exists(fileName)) { File.Delete(fileName); } File.WriteAllText(fileName, text); } catch (Exception ex) { Debug.LogException(ex); return(false); } return(true); }
private void _SaveBinary() { if (json != null) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/" + this.localKey + ".dat"); var desEncryption = new DESEncryption(); string encryptedValue = desEncryption.Encrypt(json.ToString(), enc_password); bf.Serialize(file, encryptedValue); file.Close(); } }
public string GetString(string key, string password) { string hashedKey = GenerateMD5 (key); if (PlayerPrefs.HasKey (hashedKey)) { var desEncryption = new DESEncryption (); string encryptedValue = PlayerPrefs.GetString (hashedKey); string decryptedValue; desEncryption.TryDecrypt (encryptedValue, password, out decryptedValue); return decryptedValue; } else { return ""; } }
public static string GetString(string key, string password) { string text = GenerateMD5(key); if (PlayerPrefs.HasKey(text)) { DESEncryption dESEncryption = new DESEncryption(); string @string = PlayerPrefs.GetString(text); dESEncryption.TryDecrypt(@string, password, out string plainText); return(plainText); } return(string.Empty); }
private void btnEncrypt_Click(object sender, EventArgs e) { if (tbPassword.Text.Length != 8) { WarningNotice.KeyLength(8); return; } if (tbIV.Text.Length != 8) { WarningNotice.IVLength(8); return; } tbToText.Text = DESEncryption.Encrypt(tbFromText.Text, tbPassword.Text, tbIV.Text); }
public static string GetString(string key, string password) { string text = SecurePlayerPrefs.GenerateMD5(key); if (PlayerPrefs.HasKey(text)) { DESEncryption desencryption = new DESEncryption(); string @string = PlayerPrefs.GetString(text); string result; desencryption.TryDecrypt(@string, password, out result); return(result); } return(string.Empty); }
public static bool SaveData() { const bool valid = false; try { GAME_DATA.SaveData(); var result = DESEncryption.Encrypt(JsonUtility.ToJson(SessionData.GAME_DATA)); PlayerPrefs.SetString("data", result); PlayerPrefs.Save(); } catch (Exception ex) { Debug.LogError(ex.ToString()); } return(valid); }
public static string GetString(string key, string password) { string str; string str1 = SecurePlayerPrefs.GenerateMD5(key); if (!PlayerPrefs.HasKey(str1)) { return(string.Empty); } DESEncryption dESEncryption = new DESEncryption(); string str2 = PlayerPrefs.GetString(str1); dESEncryption.TryDecrypt(str2, password, out str); return(str); }
private void btnFileSave2_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(tbPath.Text)) { WarningNotice.InputString(); return; } if (!File.Exists(tbPath.Text)) { WarningNotice.NotFound(); return; } if (tbPassword.Text.Length != 8) { WarningNotice.KeyLength(8); return; } if (tbIV.Text.Length != 8) { WarningNotice.IVLength(8); return; } if (DialogResult.OK == sfdFile.ShowDialog()) { FileInfo file = new FileInfo(tbPath.Text); FileInfo result = new FileInfo(sfdFile.FileName); fileSize = file.Length; Task.Factory.StartNew(() => { try { ControlEnable(this.Controls, false); DESEncryption.Decrypt(file, result, tbPassword.Text, tbIV.Text); this.Invoke(new Action(() => WarningNotice.Save())); } catch (Exception) { WarningNotice.WrongKey(); } finally { ControlEnable(this.Controls, true); } }); } sfdFile.FileName = ""; }
public static float GetFloat(string key, string password) { string hashedKey = GenerateMD5(key); if (PlayerPrefs.HasKey(hashedKey)) { var desEncryption = new DESEncryption(); string encryptedValue = PlayerPrefs.GetString(hashedKey); string decryptedValue; desEncryption.TryDecrypt(encryptedValue, password, out decryptedValue); return float.Parse(decryptedValue, System.Globalization.CultureInfo.InvariantCulture.NumberFormat); } else { return 0; } }
public static string GetString(string key, string password) { string hashedKey = GenerateMD5(key); if (PlayerPrefs.HasKey(hashedKey)) { var desEncryption = new DESEncryption(); string encryptedValue = PlayerPrefs.GetString(hashedKey); string decryptedValue; desEncryption.TryDecrypt(encryptedValue, password, out decryptedValue); return decryptedValue; } else { return ""; } }
private void btnDecrypt_Click(object sender, EventArgs e) { if (tbPassword.Text.Length != 8) { WarningNotice.KeyLength(8); return; } if (tbIV.Text.Length != 8) { WarningNotice.IVLength(8); return; } try { tbToText.Text = DESEncryption.Decrypt(tbFromText.Text, tbPassword.Text, tbIV.Text); } catch (Exception) { WarningNotice.WrongKey(); } }
private IEnumerator StartLoadServerList(string url) { StatusStr = string.Format("开始加载服务器列表 {0}/{1}", mRetryCnt, GlobalConst.Update.RetryTimes); Logger.Net.Log(StatusStr); bool timeout = false; float elapsedTime = 0.0f; var www = new WWW(url); yield return(www); while (!www.isDone) { elapsedTime += Time.deltaTime; if (elapsedTime >= GlobalConst.Update.Timeout) { timeout = true; break; } yield return(new WaitForFixedUpdate()); } if (!string.IsNullOrEmpty(www.error) || timeout) { if (mRetryCnt++ < GlobalConst.Update.RetryTimes) { float fWaitTime = mRetryCnt * 2 + 1; StatusStr = string.Format("加载列表失败,Err:{0},{1}秒后重试", timeout?"超时":www.error, (int)fWaitTime); Logger.Net.Log(StatusStr); yield return(new WaitForSeconds(fWaitTime)); yield return(StartCoroutine(StartLoadServerList(url))); } else { Error = true; StatusStr = string.Format("加载列表失败,Err:{0}", timeout ? "超时" : www.error); Logger.Net.LogError(StatusStr); } yield break; } var decText = www.text; #if !DISABLE_ENCRYPT_FILES && !UNITY_EDITOR decText = DESEncryption.Decrypt(decText, GlobalConst.Res.EncryptPassword); #endif var strs = decText.Split(','); if (strs.Length > 1) { StatusStr = string.Format("列表获取成功,可用节点数:{0},开始检测网络", strs.Length); Logger.Net.Log(StatusStr); foreach (var str in strs) { mNodes.Add(new ServerNode(str)); } PingAll(); } }
public byte[] Encrypt(byte[] data, byte[] Vetor, byte[] hmac) { Array.Resize(ref data, data.Length - 10); return(DESEncryption.EncryptData(data, Vetor, hmac)); }