Ejemplo n.º 1
0
        /// <summary> Saves Data into encrypted memory. </summary>
        /// <param name="pData">The Data to save, such as 'Albert', or 0, 1.5, false, and so on.</param>
        /// <param name="pKey">The key to save Data into, such as 'Albert'.</param>
        public static void SaveWeb <T>(T pData, string pKey)
        {
            ES_Data <T> saveData   = new ES_Data <T>(pData);
            string      serialized = Serialize(saveData);

            byte[] bytes;
            aes.Key = key;
            aes.GenerateIV();
            bytes = EncryptStringToBytes_Aes(serialized, aes.Key, aes.IV);
            string encrypted = GetString(bytes);

            PlayerPrefs.SetString(pKey, encrypted);
            PlayerPrefs.Save();
        }
Ejemplo n.º 2
0
        /// <summary> Saves Data into encrypted memory. </summary>
        /// <param name="pData">The Data to save, such as 'Albert', or 0, 1.5, false, and so on.</param>
        /// <param name="pPath">The Path to save Data into, such as 'Player Data/Albert'.</param>
        public static void Save <T>(T pData, string pPath)
        {
            string          dataPath  = Application.persistentDataPath + pPath + ".save";
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(dataPath, FileMode.Create);

            ES_Data <T> saveData   = new ES_Data <T>(pData);
            string      serialized = Serialize(saveData);

            byte[] bytes;
            aes.Key = key;
            aes.GenerateIV();
            bytes = EncryptStringToBytes_Aes(serialized, aes.Key, aes.IV);
            formatter.Serialize(stream, bytes);

            stream.Close();
        }
Ejemplo n.º 3
0
        /// <summary> Returns a Data object from encrypted memory, if it exists. </summary>
        /// <param name="pPath">The Path to load Data from, such as 'Player Data/Albert'.</param>
        /// <returns></returns>
        public static T Load <T>(string pPath)
        {
            string dataPath = Application.persistentDataPath + pPath + ".save";

            if (File.Exists(dataPath))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                FileStream      stream    = new FileStream(dataPath, FileMode.Open);
                byte[]          bytes     = (byte[])formatter.Deserialize(stream);
                string          decrypted;
                aes.Key = key;
                aes.GenerateIV();
                decrypted = DecryptStringFromBytes_Aes(bytes, aes.Key, aes.IV);
                ES_Data <T> Data = Deserialize <ES_Data <T> >(FixDecrypted(decrypted));
                stream.Close();
                return(Data.SaveData);
            }

            Debug.LogError("The given save file '" + pPath + "' does not exist.");
            return(default);