I am designing a mobile (iOS/Android) game and I try to save data (such as levels, coins, status) in local files.

In this way, I am concerning a case that someone can just copy these files and give them to a friend, so the friend can have achieve certain levels and all the coins held in the data files right away.

Instead of saving the data in a server, is there any way to prevent this happen?

I am thinking to encrypt the data with a key that is unique for a device. Is this a good idea or it might cause some other problem?

  • 1
    \$\begingroup\$ There's basically nothing you can do here that's worth doing. You can only prevent the most casual of hacking/save-scumming/et cetera attempts when you're not on a closed system (and even then, it's hardly a guarantee since the system can be compromised). \$\endgroup\$
    – user1430
    Apr 10 '15 at 16:15
  • \$\begingroup\$ This is somewhat different than the duplicate question. I already know I can encrypt the file. My question is not about editing the data file but copying the data file to other devices. I am wondering if there is any technique, for example, using device-specific key, then the saved data is only readable for the corresponding device. Maybe someone has other technique or maybe someone will raise issues by using device-specific keys. \$\endgroup\$
    – Joe Huang
    Apr 11 '15 at 2:10
  • 1
    \$\begingroup\$ Copying is really just a specific kind of editing where effectively-all the bytes are modified. Your "encryption" technique is defeatable because the decryption code is on the device, and thus observable, so a determined hacker can acquire a decrypted version of the data, re-encrypt it with the appropriate key for the target device, and then copy the file over there. It only takes one person to do this and release the "trainer" and it will become available to casual users. \$\endgroup\$
    – user1430
    Apr 11 '15 at 2:12
  • \$\begingroup\$ The key can be composed with the device ID plus a password only known to the developer. I know some might still can hack this but I don't mind this level of hacking. I am just wondering, saved-data copying seems a very easy/common case, has anyone had any thought to protect it or it's just a fact that we have to live with. \$\endgroup\$
    – Joe Huang
    Apr 11 '15 at 2:34
  • \$\begingroup\$ I googled a bit for a unique ID for iOS and Android. The problem seems to be that I cannot get a unique ID for a device that will never get changed. \$\endgroup\$
    – Joe Huang
    Apr 11 '15 at 2:56