Can IndexedDB be encrypted for sensitive data? How would you do that?
Ask by ICSM Computer
Updated 13 Jul 2025
Yes, IndexedDB can store encrypted data, but it does not offer encryption by default. To protect sensitive data—such as personal information, tokens, or health records—you must manually encrypt the data before storing it and decrypt it when retrieving.
Why Encrypt IndexedDB?
How to Encrypt IndexedDB Data
Here’s a step-by-step guide using the Web Crypto API, which is built into all modern browsers.
1. Generate or Import a Crypto Key
Use a symmetric key (e.g., AES-GCM) for encrypting and decrypting.
Or import an existing key:
2. Encrypt Data Before Storing
Then store this encrypted payload in IndexedDB.
3. Decrypt When Reading
4. Save and Load in IndexedDB
Here’s a basic example of saving an encrypted object:
And reading/decrypting it later:
When to Encrypt
Encrypt in IndexedDB when you:
Summary