# 🔒 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.


# 🔑 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);

# 🔐 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?

Feature When to Use It
Encryption When storing sensitive data, preventing cheating, or hiding logic
Compression When storing large strings, JSON objects, or settings payloads