0

I am looking for a way to save the users progress for my game, I am looking for something that can't be tampered with/modified. I would like to have to be able to be platform independent. And I would like it to be stored within the game files to the user can transfer their data to different computers (with a flash drive or something). (Correct me if I'm wrong in any area) But I believe because I need to to be secure and platform independent that removes player prefs from the equation. I know there is a way to save data by encrypting it with Binary, but I don't know how that works and if the user could transfer the data from computer to computer. Is there a better way of saving data? Is encrypting is through Binary the way to go? If so how would I do it? Thank you :) If you have any questions feel free to ask.

Edit: I understand nothing is completely secure, I'm looking for something that can stop the average user from going into a file, changing a float, and having tons and tons of money in game.

derHugo
  • 83,094
  • 9
  • 75
  • 115
Ultra Gamer
  • 225
  • 1
  • 4
  • 16

3 Answers3

5

The previous answer mentiones two good methods for storing data (although there are still some quirks regarding writing files on different platforms), I'd like to add on to the subject of security, as mentioned in a comment here.

First of all, nothing is fully secure, there is always someone brighter out there that will find a flaw somewhere in your code, maybe unless you want full on crypto, which is not trivial with key management etc.

I understand from the question that he wants to prevent users from moving files between machines, or allow them to move the files between machines but seal them so that users cannot easily change data stored in them.

In either case, a trivial solution would work: generate a hashcode from your dataset, mangle with it a little bit (salt it or do whatever to jump to another hashcode). so you could have something like

{
 "name"="john",
 "score"="1234",
 "protection"="043DA33C"
}

if the 'protection' field is a hashcode of "john1234", it will not match "john9999", hence if the user doesn't know how you salt your protection, you will be able to tell that the save has been tampered with

zambari
  • 4,797
  • 1
  • 12
  • 22
  • Just to clarify, I want to allow users to transfer files between machines but not tamper with the files. I understand nothing is completely secure but I'm looking for something that can stop the average user from going into a file, changing a float and being able to do anything pretty easily. – Ultra Gamer Jan 27 '19 at 07:41
  • If its okay for the users to be able to read the data, the solution I proposed will be sufficient – zambari Jan 28 '19 at 09:46
  • they will be able to modify the files, but if the checksum doesn't mach, you treat the file as invalid, so no simple modification will be effective – zambari Jan 30 '19 at 07:15
1

I found a link of data encryption tool, which is very helpful according to your need, as you want to secure data on device (nothing 100% secure), there are 3 mode to secure data, APP, Device and Encryption key, you can choose as per your need.

See this link, it may help you. https://forum.unity.com/threads/data-encryption-tool-on-assets-store.738299/

0

The first way to save data in unity is use PlayerPrefs, using for example:

PlayerPrefs.SetString("key","value");
PlayerPrefs.SetFloat("key",0.0f);
PlayerPrefs.SetInt("key",0);
PlayerPrefs.Save();

and for get, you only need

PlayerPrefs.GetString("key","default");

The second way and the way that permit you stored in a independent file is use serialization, my prefer way is a use the json file for it.

1) make a class that will store the data (not necessarily it need extends of monobehaviour:

[System.Serializable]
public class DataStorer {
  public data1:String = "default value";
  public data2:Int = 4;
  public data3:bool = true;
  ....
}

and store it in another class with

DataStorer dataStorer  = new DataStorer();
.... // some change in his data
string json = JsonUtility.ToJson(this, true);//true for you can read the file
path = Path.Combine(Application.persistantDataPath, "saved files", "data.json");
File.WriteAllText(path, json);

and for read the data

string json= File.ReadAllText(path);
DataStorer dataStorer = new DataStorer();
JsonUtility.FromJsonOverwrite(json, dataStorer);

and now you dateStorer is loaded with the data in your json file.

  • 1
    Your answer does explain saving data, but this is NOT secure. It can easilly be tampered with – Immorality Jan 26 '19 at 06:29
  • @Immorality nothing is really secure, it depends how far you want to go with secruity of your data, but for something like a game save, I recon even placing a salted checksum of the data as a field would stop most crackers – zambari Jan 26 '19 at 19:31
  • `PlayerPrefs` is *inherently insecure* as it is *not intended for save data.* It's intended to store *options* such as volume level, mute status, fullscreen or windowed, etc. Things that if the player edits the **plain text** file while the game isn't running won't cause undesired behavior. – Draco18s no longer trusts SE Jan 26 '19 at 21:44
  • @Marco Alonso Friz Palavecino Ok, where would the json file be located on the system, and I understand nothing is completely secure but is it much better than Player Prefs? – Ultra Gamer Jan 27 '19 at 07:44
  • 1
    for where it will be saved, unity had a "folder for store" in each system, it is the _persistantDataPath_ . when the player want get his file for move trow a pendrive, you can ask the folder to be stored to a player and move the file changing the _path_ string when you store the file. For add security you can add md5 or sh1 hashcode to check the integrity of your file, and you can store the file in zip format for make more hard to change – Marco Alonso Friz Palavecino Jan 27 '19 at 14:09
  • the common player, can't understand the file if it's a zip file. Responding your question a little minus. – Marco Alonso Friz Palavecino Feb 02 '19 at 12:32