IndexedDB KeyStore

In-browser key management with IndexedDB and the Web Crypto API.
Securely store and use keys for encryption, decryption, and signatures. IndexedDB and Web Crypto keep keys safe from malicious javascript.
Supports both RSA (RSA-PSS & RSA-OAEP) and Elliptic Curves (P-256, P-381 & P-521).
ECC (Elliptic Curve Cryptography) is only available on Chrome. Firefox and Safari do not support ECC and must use RSA.
Config
Below is the default config and all possible values
const defaultConfig = {
type: 'ecc',
curve: 'P-256',
rsaSize: 2048,
symmAlg: 'AES-CTR',
hashAlg: 'SHA-256',
readKeyName: 'read-key',
writeKeyName: 'write-key',
}
Note: if you don't include a crypto "type" ('ecc' | 'rsa'
), the library will check if your browser supports ECC. If so (Chrome), it will use ECC, if not (Firefox, Safari) it will fall back to RSA.
Example Usage
import KeyStore from './keystore'
const ALG = 'rsa'
await KeyStore.clear()
const ks1 = await KeyStore.init({ type: ALG, readKeyName: 'read-key-1', writeKeyName: 'write-key-1' })
const ks2 = await KeyStore.init({ type: ALG, readKeyName: 'read-key-2', writeKeyName: 'write-key-2' })
const msg = "Incididunt id ullamco et do."
const readKey1 = ks1.readKey
const readKey2 = ks2.readKey
const writeKey1 = ks1.writeKey
const sig = await ks1.sign(msg)
const valid = await ks2.verify(msg, sig, writeKey1.publicKey)
console.log('sig: ', sig)
console.log('valid: ', valid)
const cipher = await ks1.encrypt(msg, readKey2.publicKey)
const decipher = await ks2.decrypt(cipher, readKey1.publicKey)
console.log('cipher: ', cipher)
console.log('decipher: ', decipher)
const readKey = await ks1.publicReadKey()
const writeKey = await ks1.publicWriteKey()
console.log('readKey: ', readKey)
console.log('writeKey: ', writeKey)
Development
# install dependencies
yarn
# run development server
yarn start
# build
yarn build
# test
yarn test