Page 1 of 1

Change Encryption settings after game released

Posted: Tue Apr 07, 2020 6:24 am
by fanaei
Hi Joel,
I released my game without encryption on my save files.
Now I wanted to know that is it possible to add password after my game released? Can users still load their previous saves? And if not, is there any solution for adding password?

Re: Change Encryption settings after game released

Posted: Tue Apr 07, 2020 7:39 am
by Joel
Hi there,

To do this you would need to convert the files from unencrypted to encrypted when your app first loads. The easiest way to do this would be to access the file with encrypted settings inside a try/catch block. If you catch an exception, use ES3.LoadRawString to load the file with unencrypted settings, and then use ES3.SaveRaw with encrypted settings to save it back to file with encryption.

Something along the lines of:
var unencryptedSettings = new ES3Settings(ES3.EncryptionType.None, "");
var encryptedSettings = new ES3Settings(ES3.EncryptionType.AES, "myPassword");

try
{
    ES3.KeyExists("key", "SaveFile.es3", encryptedSettings);
}
catch(System.Security.Cryptography.CryptographicException)
{
    var unencryptedData = ES3.LoadRawString("SaveFile.es3", unencryptedSettings);
    ES3.SaveRaw(unencryptedData, "SaveFile.es3", encryptedSettings);
}
All the best,
Joel