A library for transparently encrypting model attributes in ORMs or standalone, using AES-256-GCM with 96-bit random nonces and 128-bit authentication tags. Version 1.1.0 is the current stable release, maintained as needed. Supports key rotation via key IDs and additional authenticated data (key id, object id) to prevent substitution attacks. Designed for Node.js ≥4.0, ESM-only? No, CommonJS-based. Differentiator: explicit security and threat models, integration with ORM hooks, and use of standard Node.js crypto.
npm install encrypted-attrNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows stand-alone encryption and decryption of an attribute using random key and an object id for AAD.
Use crypto.randomBytes(32).toString('base64') to generate keys.Always provide a unique object ID (e.g., model ID) when encrypting/decrypting per-record attributes.
Manage keys via environment variables, vault, or keychain. Never commit keys to source control.
Combine with secure coding practices (sanitize input, avoid logging secrets) and use transport encryption.
Ensure keys are base64-encoded strings from 32 random bytes.
Use the same key that was used for encryption. If rotating keys, use key id mechanism.
Use const EncryptedAttributes = require('encrypted-attr');