public static void SetFloat(string key, float value) { var encryptedKey = UserEncryption.EncryptString(key); var encryptedValue = UserEncryption.EncryptFloat(value); PlayerPrefs.SetString(KeyPrefix + encryptedKey, ValueFloatPrefix + encryptedValue); }
public static void SetString(string key, string value) { var encryptedKey = UserEncryption.EncryptString(key); var encryptedValue = UserEncryption.EncryptString(value); PlayerPrefs.SetString(KeyPrefix + encryptedKey, ValueStringPrefix + encryptedValue); }
public static string DecryptKey(string encryptedKey) { if (encryptedKey.StartsWith(KeyPrefix)) { var strippedKey = encryptedKey.Substring(KeyPrefix.Length); return(UserEncryption.DecryptString(strippedKey)); } throw new InvalidOperationException( "Could not decrypt item, no match found in known encrypted key prefixes"); }
public static int GetInt(string key, int defaultValue = 0) { var encryptedKey = KeyPrefix + UserEncryption.EncryptString(key); var fetchedString = PlayerPrefs.GetString(encryptedKey); if (string.IsNullOrEmpty(fetchedString)) { return(defaultValue); } fetchedString = fetchedString.Remove(0, 1); return(UserEncryption.DecryptInt(fetchedString)); }
public static object GetValue(string encryptedKey, string encryptedValue) { if (encryptedValue.StartsWith(ValueFloatPrefix)) { return(GetFloat(UserEncryption.DecryptString(encryptedKey.Substring(KeyPrefix.Length)))); } if (encryptedValue.StartsWith(ValueIntPrefix)) { return(GetInt(UserEncryption.DecryptString(encryptedKey.Substring(KeyPrefix.Length)))); } if (encryptedValue.StartsWith(ValueStringPrefix)) { return(GetString(UserEncryption.DecryptString(encryptedKey.Substring(KeyPrefix.Length)))); } throw new InvalidOperationException( "Could not decrypt item, no match found in known encrypted key prefixes"); }