litle-indexeddb
v1.0.1
Published
IndexedDb with AES-GCM encryption
Readme
Little Indexed DB
Standard indexeddb on browsers store data in plain text. Attackers can steal your tokens or other PIN (personally identifiable information) from your browser.
little-IndexedDB is just a wrapper around indexedDB, it encrypts JSON-serializable with AES-GCM-256 encryption.
Note: Keys are not encrypted for indexing purposes.
Also, your application does not become immmune to client-side data-leaks from this. Due to the mutable qurik (curse) of JavaScript, any kind of XSS (Cross-Site-Scripting) is more than enough to steal the data. Though it depends on how you handle the crypto key.
Usage
Use directly through esm.sh cdn:
<script type="module">
import LittleIndexedDB from 'https://esm.sh/little-indexeddb';
const db = new LittleIndexedDB('AppDB', 'auth_store');
const pin = prompt('Enter your security PIN:');
if (!pin) throw new Error('PIN is required to unlock storage.');
await db.init(pin);
try {
// For this example, I'm storing the user's auth tokens.
await db.setItem('session', {
name: 'Alex Mercer',
accessToken: 'eyJh...token',
refreshToken: 'rt_9823...secret'
});
const session = await db.getItem('session');
console.log('Decrypted user:', session.name);
} catch (err) {
console.error('Decryption failed: ', err);
} finally {
db.close(); // Closing is good.
}
</script>