Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Redot.

Encrypting save gamesΒΆ

The class FileAccess can open a file at a location and read/write data (integers, strings and variants). It also supports encryption. To create an encrypted file, a passphrase must be provided, like this:

var f = FileAccess.open_encrypted_with_pass("user://savedata.bin", FileAccess.WRITE, "mypass")
f.store_var(game_state)

This will make the file unreadable to users, but will still not prevent them from sharing savefiles. To solve this, use the device unique id or some unique user identifier, for example:

var f = FileAccess.open_encrypted_with_pass("user://savedata.bin", FileAccess.WRITE, OS.get_unique_id())
f.store_var(game_state)

Note that OS.get_unique_id() does not work on UWP or HTML5.

Note

This method cannot really prevent players from editing their savegames locally because, since the encryption key is stored inside the game, the player can still decrypt and edit the file themselves. The only way to prevent this from being possible is to store the save data on a remote server, where players can only make authorized changes to their save data. If your game deals with real money, you need to be doing this anyway.