Skip to content
Türkçe

Introducing Magic Encryption 1.0.2

Keep a value opaque at rest on the device.

AES-256-CBC for apps on the Magic framework, through the Crypt facade. Payloads are not authenticated and not compatible with Laravel's encrypter.

One facade. Two keys.

Crypt encrypts with your APP_KEY or with a per-device key kept in Vault. It keeps a value opaque at rest; it does not authenticate it.

  • Encrypt and decrypt

    Crypt.encrypt(value) and Crypt.decrypt(payload) use the app key, with AES-256 in CBC mode and PKCS7 padding.

    Learn more about Encrypt and decrypt
  • The app key

    The key is 32 raw characters or a base64: value that decodes to 32 bytes. The encrypter resolves it lazily from app.key. The key ships inside every build, so it hides a value from someone without the app, not from someone who unpacks it.

    Learn more about The app key
  • A per-device key

    Crypt.encryptWithDeviceKey and Crypt.decryptWithDeviceKey use a key kept in Vault. Manage it with hasDeviceKey, generateDeviceKey and clearDeviceKey.

    Learn more about A per-device key
  • What is on the wire

    Every call uses a fresh random 16-byte IV, and the payload is base64(iv):base64(ciphertext). It has no MAC, no key id and no rotation, and it is not Laravel's format.

    Learn more about What is on the wire
  • Errors are exceptions

    A payload that cannot be decrypted throws MagicDecryptException. Encrypting an empty string throws a RangeError.

    Learn more about Errors are exceptions
  • Generate the key

    dart run magic:dowel key:generate writes APP_KEY=base64:... into .env. Pass --show to print the key instead. It replaces any existing key, and values encrypted under the old one become unreadable.

    Learn more about Generate the key

Add it in seconds

~/my_app
flutter pub add magic_encryption

Or add to pubspec.yaml:

dependencies:
  magic_encryption: ^1.0.2

Or give your AI agent this prompt:

Read https://anilcancakir.com/magic/docs/encryption/llms.txt and install the Magic Encryption package in this project.