#
🔒 Encryption & Compression
EazyPrefs makes it easy to keep your saved data safe, compact, and tamper-resistant with built-in support for encryption and compression. These features are optional and can be applied per pref, giving you full control over what gets protected and how.
You can enable whether new prefs should be automatically encrypted and/or compressed from the Settings tab in the EazyPrefs Editor.
#
🔑 Encrypting & Compressing a Pref
Encryption and compression are available when using instance-based access. You can either:
- Specify encryption and compression when setting a new value, or
- Toggle them independently at any time.
var source = new PlayerPrefStorageSource("MySecret");
var pref = new StringPref(source);
// Set a new value, and define whether it should be encrypted and/or compressed
pref.SetValue("TopSecretValue", encrypted: true, compressed: true);
// Or just toggle encryption/compression independently.
pref.SetEncrypted(true);
pref.SetCompressed(true);
Calling SetValue()
without specifying encrypted and/or compressed will apply the current encryption/compression settings of the pref.
Toggling encryption or compression independently will automatically update and store the value in its new form.
It's always more optimized to use:
SetValue(value, encrypted: true, compressed: true)
rather than calling SetValue(value)
followed by SetEncrypted(...)
or SetCompressed(...)
.
Use the individual methods only when you're changing encryption/compression independently, not in the same step as setting a value.
#
🔐 How It Works
- Encryption is performed using AES (Advanced Encryption Standard) — a widely-used and secure symmetric encryption algorithm.
- Compression uses GZip, which significantly reduces data size, especially for JSON or large strings.
Both processes are applied after serialization, meaning they wrap the entire stored value — whether it's a primitive or a complex object.
#
⚙️ When Should You Use It?
Enable encryption to protect gameplay data, configurations, or player info from tampering. Enable compression to keep stored data size low — especially useful for structured or verbose data.