1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- .. _doc_encrypting_save_games:
- Encrypting save games
- =====================
- Why?
- ----
- The class :ref:`File <class_File>` 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:
- .. tabs::
- .. code-tab:: gdscript GDScript
- var f = File.new()
- var err = f.open_encrypted_with_pass("user://savedata.bin", File.WRITE, "mypass")
- f.store_var(game_state)
- f.close()
- .. code-tab:: csharp
- var f = new File();
- var err = f.OpenEncryptedWithPass("user://savedata.bin", (int)File.ModeFlags.Write, "mypass");
- f.StoreVar(gameState);
- f.Close();
- This will make the file unreadable to users, but will still not prevent
- them sharing save files. To solve this, use the device unique id or
- some unique user identifier, for example:
- .. tabs::
- .. code-tab:: gdscript GDScript
- var f = File.new()
- var err = f.open_encrypted_with_pass("user://savedata.bin", File.WRITE, OS.get_unique_id())
- f.store_var(game_state)
- f.close()
- .. code-tab:: csharp
- var f = new File();
- var err = f.OpenEncryptedWithPass("user://savedata.bin", (int)File.ModeFlags.Write, OS.GetUniqueId());
- f.StoreVar(gameState);
- f.Close();
- Note that ``OS.get_unique_ID()`` only works on iOS and Android.
- This is all! Thanks for your cooperation, citizen.
|