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
Learn more about Encrypt and decryptCrypt.encrypt(value)andCrypt.decrypt(payload)use the app key, with AES-256 in CBC mode and PKCS7 padding. -
The app key
The key is 32 raw characters or a
Learn more about The app keybase64:value that decodes to 32 bytes. The encrypter resolves it lazily fromapp.key. The key ships inside every build, so it hides a value from someone without the app, not from someone who unpacks it. -
A per-device key
Learn more about A per-device keyCrypt.encryptWithDeviceKeyandCrypt.decryptWithDeviceKeyuse a key kept in Vault. Manage it withhasDeviceKey,generateDeviceKeyandclearDeviceKey. -
What is on the wire
Every call uses a fresh random 16-byte IV, and the payload is
Learn more about What is on the wirebase64(iv):base64(ciphertext). It has no MAC, no key id and no rotation, and it is not Laravel's format. -
Errors are exceptions
A payload that cannot be decrypted throws
Learn more about Errors are exceptionsMagicDecryptException. Encrypting an empty string throws aRangeError. -
Generate the key
Learn more about Generate the keydart run magic:dowel key:generatewritesAPP_KEY=base64:...into.env. Pass--showto print the key instead. It replaces any existing key, and values encrypted under the old one become unreadable.
Add it in seconds
Or add to pubspec.yaml:
dependencies:
magic_encryption: ^1.0.2
Or give your AI agent this prompt: