Skip to content

Encryption

The Save System can encrypt the files it writes. This page says what that protects and what it does not.

Encryption stops accidental damage and casual editing of a save file. When someone changes or damages an encrypted file, the load refuses it instead of loading it half-way.

It does not stop a determined person. The password ships inside your game, so anyone who can run the game can read it out. And while Accept Plain Saves is on, which is the default, a plain JSON save loads too, so a player can replace an encrypted file with plain text.

Two more things stay readable. The header of a save is never encrypted, so anyone can read the title, the day, the scene and the list of your parts. A secret part’s content is encrypted, but its key is listed.

On the Save System component:

Setting Default What it does
Encrypt off Encrypts the new save files.
Encryption Password My Password The password that encrypts and opens the files. Choose your own.
Accept Plain Saves on With Encrypt on, still load a save that is not encrypted. Off refuses it with the status Unprotected.

sources: Runtime/Save/IntrigueSaveSystem.cs.

  1. Replace the password with your own. The one that ships is My Password. With Encrypt on, the Save System logs a warning while you keep it.
  2. Turn Encrypt on.
  3. Decide on Accept Plain Saves. On keeps the saves written before you switched encryption on. Off refuses them. Even off, it is not protection against a determined person.

If Encrypt is on and the password is empty, a save is refused with EncodeFailed before anything is captured.

Saves you already wrote stay loadable whatever Encrypt says, but if you change the password, the old encrypted saves no longer open.

If your password should not sit in a scene, set IntrigueSaveSystem.Instance.PasswordSource to a function that returns it. When it is not null, it is used in place of the field.

From SaveCipher.cs and ISaveProtector.cs: AES-256 in CBC mode with PKCS7 padding, authenticated with HMAC-SHA256 (encrypt, then MAC). PBKDF2 (HMAC-SHA256, 60,000 rounds, a random 16-byte salt) turns the password into the key. Salt and IV are random for every file, so the same save encrypts to different bytes each time. The code checks the tag in constant time before it decrypts anything. It uses only System.Security.Cryptography of the platform and no reflection, which the code gives as the reason IL2CPP and AOT builds should be fine. No player build has been checked.

You can write your own protector. ISaveProtector has Kind, Ready, TryProtect and TryUnprotect. Only a protector of the same kind opens a save. A protector that also implements IThreadSafeSaveProtector can run on a worker thread. The built-in SaveCipherProtector is public and takes a password or a function that returns one.

Encrypting derives a key. The README gives:

Where Per key
Unity editor about 170 ms
Offline test about 25 ms

With Encrypt on and secret parts, a save derives two keys. The Save System does this on a worker thread, so the game does not stop for it. On WebGL, which has no worker threads, it stays on the main thread. Phones were not measured. The code’s own comment says a phone is probably several times slower and advises measuring in a player build.

A secret save part uses the same password, even in a file that is otherwise plain. A save with a secret part is refused while the password is empty or still the one that ships. See Your own data in a save.