示例#1
0
        /// <summary>
        /// Store a string encrypted. hashKey should be setted properly
        /// </summary>
        public static void SetStringSecure(string key, string val)
        {
            var encryptMode = EncryptionMode.SIMPLE;

            PlayerPrefs.SetInt(EncryptionModeKey, (int)EncryptionMode.SIMPLE);

            string cipherStr;

            switch (encryptMode)
            {
            case EncryptionMode.PLAIN:
                SetString(key, val);
                break;

            case EncryptionMode.SIMPLE:
                cipherStr = SimpleEncryptUtil.EncryptString(val);
                PlayerPrefs.SetString(key, cipherStr);
                break;

            case EncryptionMode.RIJNDAE:
                cipherStr = RijndaelEncryptUtil.EncryptString(val);
                PlayerPrefs.SetString(key, cipherStr);
                break;
            }
        }
示例#2
0
        /// <summary>
        /// Decrypt the specified string. hashKey should be setted properly
        /// </summary>
        public static string GetStringSecure(string key, string defVal = null)
        {
            var encryptMode = (EncryptionMode)PlayerPrefs.GetInt(EncryptionModeKey, (int)EncryptionMode.SIMPLE);

            switch (encryptMode)
            {
            case EncryptionMode.PLAIN:
                return(GetString(key, defVal));

            case EncryptionMode.SIMPLE:
                if (PlayerPrefs.HasKey(key))
                {
                    string cipherStr = PlayerPrefs.GetString(key);
                    return(SimpleEncryptUtil.DecryptString(cipherStr));
                }
                else
                {
                    return(defVal);
                }

            case EncryptionMode.RIJNDAE:
                if (PlayerPrefs.HasKey(key))
                {
                    string cipherStr = PlayerPrefs.GetString(key);
                    return(RijndaelEncryptUtil.DecryptString(cipherStr));
                }
                else
                {
                    return(defVal);
                }
            }

            return(null);
        }