コード例 #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);
        }