0.0.8 • Published 7 years ago
@sepior/mongoose-sepior v0.0.8
node-mongoose-sepior
A super simple mongoose plugin using Sepior to encrypt a field before saving it to the database.
Install
Install this with npm
npm install --save @sepior/mongoose-sepior
Usage
Given some schema, you can enable Sepior for this by adding the plugin.
const { SepiorServicesClient } = require('@sepior/sdk')
const mongooseSepior = require('@sepior/mongoose-sepior')
const sepiorClient = SepiorServicesClient.createPasswordBasedClient( ... ) // Create a Sepior client
const ttl = 60 * 60 // Optional TTL in seconds. Default 3600
const IContainStupidSecretStuffSchema = new Schema({ ... }) // Define schema
IContainStupidSecretStuffSchema.plugin(mongooseSepior, { sepiorClient }); // Add plugin to schema
This will add two fields to your schema. decryptedData
and encrypted
respectively.
The first field will not be saved to the database but will be encrypted and
saved in the encrypted
field. When initializing the document, the decryptedData
field will be populated.
Too make everything a bit more efficient the encryption result is cached in memory.