Esempio n. 1
0
        public static void SetFloat(string key, float value)
        {
            var encryptedKey   = UserEncryption.EncryptString(key);
            var encryptedValue = UserEncryption.EncryptFloat(value);

            PlayerPrefs.SetString(KeyPrefix + encryptedKey, ValueFloatPrefix + encryptedValue);
        }
Esempio n. 2
0
        public static void SetString(string key, string value)
        {
            var encryptedKey   = UserEncryption.EncryptString(key);
            var encryptedValue = UserEncryption.EncryptString(value);

            PlayerPrefs.SetString(KeyPrefix + encryptedKey, ValueStringPrefix + encryptedValue);
        }
Esempio n. 3
0
        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");
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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");
        }