I have mongoDb database, I want all data to be encrypted, how we can do this by using nodejs. All the key values should be encrypted.
2 Answers
This is not a concern with MongoDB. You can encrypt the data before storing it regardless of DB and maintain a master key.
Encryption is a two way process that uses a hidden secret key to encrypt/decrypt. As long as you know the master key you can decrypt. So prior to storing in Mongo encrypt plain text or objects. And when you want to read decrypt.
You'll add a performance overhead to encrypt/decrypt all your data. And you'll loose the ability to query data freely. But if it's sensitive user data you're taking the right path. As long as your master KEY is kept secret even if your database is stolen the data is still safe.
Take a look at this article https://lollyrock.com/posts/nodejs-encryption/ , and set up a dummy node project to test it out. Try encrypting and decrypting and print out the output.
Comments
MongoDB Enterprise provides you option to encrypt the database.
You can use Mongoose-encryption package for simple encryption and authentication of mongoose documents.
2 Comments
findOne() is expected to work. But,if you had encrypted multiple documents at once,as per documentation, you cannot select individual encrypted fields in a query nor unset or rename encrypted fields via an update operation.
encryptplain text or objects. And when you want to readdecrypt