prinzhorn / mongoose-encrypt Goto Github PK
View Code? Open in Web Editor NEWTransparent encryption for Mongoose fields with built-in password migration
License: MIT License
Transparent encryption for Mongoose fields with built-in password migration
License: MIT License
Please add mongoose-encrypt to the npm registry, so we can install it easily
Funny what you find after reading the code again after two months https://github.com/Prinzhorn/mongoose-encrypt/blob/master/test/index.js#L40 (the password
option expect a function, e.g. Math.random
not Math.random()
). Probably masked like #3
Everything is working but the getter doesn't seem to always be applied. Maybe you can shed some light if this is intended behaviour or not.
For example.
User.find({}).exec( function( err, collection ) {
res.send( collection );
});
In this case the getters for encrypted fields within documents within that collection are not applied and the data is not decrypted.
But if I do targeted call like below, the getter is triggered and I get decrypted data back:
res.send( collection[0].firstName );
Currently I have been able to work around this issue by doing:
User.find({}).exec( function( err, collection ) {
var finalCollection = [];
collection.forEach( function ( doc ) {
finalCollection.push( doc.toJSON({ getters : true }) );
});
res.send( collection );
});
But I am uncertain if it should be possible to just have it work automatically on find() that returns several documents... Really not much documentation in mongoose API about whether or not this is intended behaviour or if there is something wrong on my part. Perhaps you know?
For some reason the tests are doing this already https://github.com/Prinzhorn/mongoose-encrypt/blob/master/test/index.js#L39 but the lib doesn't support it https://github.com/Prinzhorn/mongoose-encrypt/blob/master/lib/index.js#L120 (it's never turned into an array). I guess assert.throws
masks this error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.