magic-encryption
Skill3 starsChanged 17 days agoMITView on GitHub
Encrypt and decrypt strings in a Magic app with the Crypt facade, an APP_KEY or a Vault-backed device key.
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- anilcancakir/aiword for word, first seen Nov 16, 2026
Other versions1 project uses a version of this.
Word for word · 1
- anilcancakir/ai★ 3100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository19 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- crumbsSkill
- dowelSkill
- flutter-reviewSkill
- magic-analyticsSkill
- magic-deeplinkSkill
- magic-deviceSkill
- magic-devtoolsSkill
- magic-frameworkSkill
- magic-local-storageSkill
- magic-notificationsSkill
- magic-paymentsSkill
- magic-pickerSkill
- magic-sentrySkill
- magic-social-authSkill
- magic-socketSkill
- magic-starterSkill
- tapirSkill
- wind-uiSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 27
Never call Crypt.encrypt('').
- Very specific: line 31
Treat Crypt as confidentiality at rest and nothing more.
- Very specific: line 36
Create APP_KEY with dart run magic:dowel key:generate: it writes APP_KEY=base64:<32 random bytes> to .env.
- Distinctive: line 64
Keep a token on the device only:
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
magic_encryption
AES-256-CBC for a Magic app. The Crypt facade encrypts a String with the configured app.key (encrypt, decrypt, synchronous) or with a per-device key kept in Vault (encryptWithDeviceKey, decryptWithDeviceKey, async). EncryptionServiceProvider binds the cipher; key:generate writes APP_KEY. The payload is base64(iv):base64(ciphertext), carries no MAC and is not Laravel's format.
This skill covers magic_encryption only. The Magic framework itself (container, facades, Vault, config) is the magic-framework skill.
Install
flutter pub add magic_encryption
dart run magic:dowel plugin:install magic_encryption
dart run magic:dowel key:generateRequires Dart >=3.13, Flutter >=3.47 and magic ^1.0.0. The installer registers EncryptionServiceProvider in lib/config/app.dart and publishes no config, because magic:install already wires 'key': env('APP_KEY'). It never runs key:generate. Import only the barrel: package:magic_encryption/magic_encryption.dart.
Crypt rules
- Register
EncryptionServiceProviderinprovidersbefore callingCrypt.encryptorCrypt.decrypt: it is not auto-registered, and the facade resolves theencrypterbinding it creates inboot(). CallCryptafterMagic.initcompletes. - Never call
Crypt.encrypt(''). An empty string throwsRangeError, because there is no block to pad. Guard the call. Crypttakes and returns aString. Encode aMaporListwithjsonEncodebefore andjsonDecodeafter.- Catch
MagicDecryptExceptionfromdecryptand answer the party that sent the payload with one generic error. Different failures shown to a sender are what a padding oracle is built from. - A missing or wrong-size
app.keydoes not fail boot. The firstCryptcall throws anException. A raw key is 32 bytes of UTF-8 (32 characters for ASCII); abase64:key decodes to 32 bytes. - Treat
Cryptas confidentiality at rest and nothing more. There is no MAC, so a payload that decrypts is not proven untampered, and CBC is malleable. Verify a token, an amount or an identity on the server that issued it. - A payload from the wrong key almost always throws
MagicDecryptException, but about one in 256 unpads cleanly and returns garbage text. Do not use a decrypt that did not throw as a key check.
Key rules
- Create
APP_KEYwithdart run magic:dowel key:generate: it writesAPP_KEY=base64:<32 random bytes>to.env.--showprints it and leaves.envalone. Never commit it. key:generatereplaces any existingAPP_KEY, and every value encrypted under the old key becomes unreadable. Never run it on an app with stored ciphertext. The payload has no key id, so there is no rotation: migrate by decrypting withMagicEncrypter.fromAppKey(oldKey)and encrypting again withCrypt.encrypt.- Device-key mode needs core's
VaultServiceProviderand needs noapp.key. The key is 32 random alphanumeric characters stored inVaultasmagic:device_encryption_key, created on first use and cached in a static field. generateDeviceKey()andclearDeviceKey()orphan everything encrypted under the old device key. The key is lost when its secure storage entry is removed (on Android also by an uninstall; on iOS the Keychain item can survive a reinstall), so keep only data you can recreate.- A
Crypt.encryptpayload and a device-key payload do not open each other's: keep a value with the mode that wrote it.
Wire format
AES-256 in CBC mode, PKCS7 padding, key bytes either the UTF-8 bytes of a raw string (32 bytes, 32 characters for ASCII) or the 32 decoded bytes of a base64: key, a random 16-byte IV per call, UTF-8 plaintext, payload base64(iv):base64(ciphertext). It is the format Magic 0.0.41 and earlier wrote, so it never changes. It is not Laravel's JSON-with-HMAC payload: neither side reads the other's. MagicEncrypter.encrypt has an iv: parameter for tests only.
Recipes
Encrypt and decrypt with the app key:
import 'package:magic_encryption/magic_encryption.dart';
String? open(String payload) {
try {
return Crypt.decrypt(payload);
} on MagicDecryptException {
return null; // Log it; do not tell the sender why.
}
}
String seal(String value) => Crypt.encrypt(value);Keep a token on the device only:
import 'package:magic_encryption/magic_encryption.dart';
Future<String> store(String token) => Crypt.encryptWithDeviceKey(token);
Future<String> load(String stored) => Crypt.decryptWithDeviceKey(stored);Testing
No mocking library is needed. In setUp() call MagicApp.reset() and Magic.flush(), then bind a cipher with Magic.singleton('encrypter', () => MagicEncrypter('0123456789abcdef0123456789abcdef')) for config-key mode, or Vault.fake() for device-key mode. Crypt caches the device encrypter in a static field that Magic.flush() does not reset, so call await Crypt.clearDeviceKey() in tearDown(). Do not assert that a wrong-key payload throws, since about one in 256 does not; assert it never yields the plaintext. Pin the IV with encrypt(value, iv: Uint8List(16)) to assert an exact payload.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

