Registry / security / encrypt-storage

encrypt-storage

JSON →
library2.14.7jsnpmunverified

A wrapper for native browser Storage (localStorage/sessionStorage) that encrypts data using crypto-js. Current stable version is 2.14.7, released frequently (multiple minor versions per month). It automatically encrypts and decrypts values, supports multiple storage instances, and allows configuration of encryption algorithm, prefix, and state management hooks. Unlike simple base64 encoding libraries, encrypt-storage uses AES encryption with a user-provided secret key, making it harder for casual users to read data from the console. However, as noted in the docs, nothing on the frontend is truly secure as the key is exposed. Ships TypeScript types. This is the v2 line with breaking changes from v1.

npm install encrypt-storage
INSTALL
IMPORT
SIG · ENCRYPT-STORAGE
E
encrypt-storage
securityjavascriptv2.14.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

EncryptStorage
import { EncryptStorage } from 'encrypt-storage';
const EncryptStorage = require('encrypt-storage').EncryptStorage;
The package supports both ESM and CommonJS. In Node.js with CommonJS, use destructured require.
default
import EncryptStorage from 'encrypt-storage';
import { default as EncryptStorage } from 'encrypt-storage';
Default export is provided for convenience, but named export is preferred for clarity.
IEncryptStorageOptions
import type { IEncryptStorageOptions } from 'encrypt-storage';
import { IEncryptStorageOptions } from 'encrypt-storage';
This is a TypeScript type/interface; use `import type` for runtime performance. Available in v2+.
encrypt-storage (CDN)
<script src="https://cdn.jsdelivr.net/npm/encrypt-storage@2.14.7/dist/encrypt-storage.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/encrypt-storage@1.3.0/dist/encrypt-storage.js"></script>
UMD bundle exposes `EncryptStorage` globally. Use v2+ for latest features; do not use old v1 CDN.

Shows how to initialize EncryptStorage with a secret key and options, then set/get/remove single and multiple items.

import { EncryptStorage } from 'encrypt-storage'; const secretKey = process.env.SECRET_KEY ?? 'my-secret-key'; const encryptedLocalStorage = new EncryptStorage(secretKey, { prefix: '@encrypted', storageType: 'localStorage', stateManagementUse: true, encAlgorithm: 'AES', doNotEncryptValues: [] }); encryptedLocalStorage.setItem('user', { name: 'John', surname: 'Doe' }); const user = encryptedLocalStorage.getItem('user'); console.log(user); // { name: 'John', surname: 'Doe' } encryptedLocalStorage.removeItem('user'); // Multiple items encryptedLocalStorage.setMultipleItems({ key1: 'value1', key2: { nested: true } }); const [val1, val2] = encryptedLocalStorage.getMultipleItems(['key1', 'key2']); console.log(val1, val2); encryptedLocalStorage.removeItem('key1');
Debug
Known issues
breakingv2 has breaking changes from v1. Options like `_prefix` renamed to `prefix`, `_storageType` to `storageType`, and method signatures changed.
fix
Refer to migration guide in docs. Update options object keys and method calls to v2 API.
affects: >=2.0.0
deprecatedThe `encAlgorithm` option with value 'TripleDES' is deprecated in favor of 'AES' due to security concerns.
fix
Use encAlgorithm: 'AES' instead of 'TripleDES'.
affects: >=2.10.0
gotchaSecret key is stored in plain text in client-side code. Anyone with access to the source can decrypt the storage.
fix
Understand that this provides obfuscation, not real security. Do not store truly sensitive data.
affects: *
gotchaIf `stateManagementUse` is set to true, the library will automatically encrypt/decrypt on every set/get, which can impact performance if called frequently.
fix
Set stateManagementUse to false if you manage state manually, or batch updates.
affects: *
gotchaThe `doNotEncryptValues` option expects an array of string values that should be stored in plain text. If a value matches exactly, it will not be encrypted. This can be a security risk if misconfigured.
fix
Ensure doNotEncryptValues does not contain any sensitive data patterns.
affects: >=2.0.0
Errors
Common errors & fixes
Error: secretKey is required
Missing or undefined secretKey argument passed to EncryptStorage constructor.
fix
Ensure you pass a non-empty string as the first argument: `new EncryptStorage('my-secret-key')`
TypeError: localStorage is not defined
Code is running in a non-browser environment (e.g., Node.js server-side rendering).
fix
Use an alternative storage or wrap in a check for `typeof window !== 'undefined'`.
Error: Invalid JSON: ...
Trying to getItem for a key that was set without encryption (e.g., via native localStorage.setItem) and the value is not valid JSON.
fix
Use EncryptStorage methods consistently, or catch and parse the raw value.
Upgrade
Version history
2.14.7latest on npm
Audit
Dependencies
crypto-jsrequiredProvides the encryption algorithms (AES, TripleDES, etc.) used to encrypt storage data.
Agent activity
23 hits · last 30 days
node
20
Amazon
1
OpenAI (training)
1
Resources
encrypt-storage — npm install encrypt-storage · libregistry