All Projects → eykrehbein → Mongocrypt

eykrehbein / Mongocrypt

Licence: mit
An encryption library for node.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Mongocrypt

Express Boilerplate
🚀 Starter project for a RESTful API in Node with Express & mongoose component-based
Stars: ✭ 9 (-68.97%)
Mutual labels:  mongodb
Summary
个人总结 持续更新 欢迎提出各种issues
Stars: ✭ 12 (-58.62%)
Mutual labels:  mongodb
Shopify Mern Boilerplate
A Boilerplate for creating MERN stack Shopify app.
Stars: ✭ 20 (-31.03%)
Mutual labels:  mongodb
Iniciando Mongodb
Dicas e comandos de Mongodb para usar diretamente no terminal/command
Stars: ✭ 9 (-68.97%)
Mutual labels:  mongodb
Netkiller.github.io
Netkiller Free ebook - 免费电子书
Stars: ✭ 861 (+2868.97%)
Mutual labels:  mongodb
Diagonistician Reactjs Express Mongoose
Question - Answers demo SPA
Stars: ✭ 13 (-55.17%)
Mutual labels:  mongodb
Springbootunity
rabbitmq、redis、scheduled、socket、mongodb、Swagger2、spring data jpa、Thymeleaf、freemarker etc. (muti module spring boot project) (with spring boot framework,different bussiness scence with different technology。)
Stars: ✭ 845 (+2813.79%)
Mutual labels:  mongodb
P2p
一个基于 python 的 flask 框架的资讯网站, http://119.29.100.53:8086/
Stars: ✭ 28 (-3.45%)
Mutual labels:  mongodb
Much Assembly Required
Assembly programming game
Stars: ✭ 869 (+2896.55%)
Mutual labels:  mongodb
Treefrog Framework
TreeFrog Framework : High-speed C++ MVC Framework for Web Application
Stars: ✭ 885 (+2951.72%)
Mutual labels:  mongodb
Js Data Mongodb
MongoDB adapter for js-data. Main Site: http://js-data.io, API Reference Docs: http://api.js-data.io
Stars: ✭ 9 (-68.97%)
Mutual labels:  mongodb
Node Auth
基于 Node Express Mongoose 实现的用户注册/登陆权限验证
Stars: ✭ 10 (-65.52%)
Mutual labels:  mongodb
Led
LED ( Logs Explorer for Docker ) is a tool used for visualizing and exploring docker container logs
Stars: ✭ 13 (-55.17%)
Mutual labels:  mongodb
Social Listener
Python project used to collect tweets and social-network data from Social's API
Stars: ✭ 9 (-68.97%)
Mutual labels:  mongodb
Bibi
An e-commerce fullstack solution for Flask 出口电商全栈解决方案
Stars: ✭ 914 (+3051.72%)
Mutual labels:  mongodb
Mongodb Utils
MongoDB utils library for Node.js
Stars: ✭ 9 (-68.97%)
Mutual labels:  mongodb
Neural Network Digit Ocr
Trains a Neural Network to read handwritten digits (OCR). Uses synaptic for Node.js, socket.io and MongoDB
Stars: ✭ 12 (-58.62%)
Mutual labels:  mongodb
Placementmnit
Official Placement Portal : MNIT Jaipur
Stars: ✭ 29 (+0%)
Mutual labels:  mongodb
Project16 B Account Book
👥👤👥뭐야..👤👥👥👤👥👤 이거쓰면 부자된다고..?👥👤👥👤👤👥👥 웅성웅성..👤👥👤👥👤궁금하다..👥👥👤👥
Stars: ✭ 28 (-3.45%)
Mutual labels:  mongodb
Go Mongodbatlas
A Go client library for the MongoDB Atlas API
Stars: ✭ 15 (-48.28%)
Mutual labels:  mongodb

mongocrypt

MongoCrypt is an encryption library for node.js

An example database entry without MongoCrypt:

example without mongocrypt

The same database entry with MongoCrypt:

example without mongocrypt

Introduction

MongoCrypt is a service to encrypt and decrypt your data stored in a MongoDB database. It was also designed with these principles in mind:

  • Lightweight: With a 20KB index.js it's a pretty lightweight library. No unnecessary functions are included so you can care less about this encryption and concentrate more on you task.
  • Easy to use: It was designed on top of the MongoDB SDK for node.js and it uses almost identical functions. The findOne function compared:
   const collection = "users";
   const query = {name: "eykjs"}

   // with mongodb's sdk
   db.collection(collection).findOne(query, (err, res) => {
       if(!err){
           console.log("Email: " + res.email);
       }else{
           console.log("Error!");
       }
   });

   // with mongocrypt
   mongocrypt.db.collection(collection).findOne(query).then(res => {
       if(res){
           console.log("Email: " + res.email);
       }else{
           console.log("Error!");
       }
   });
  • Fast & Safe: On average mongocrypt is just 5-15ms slower than the MongoDB SDK (depending on the amount and size of your input values) but a lot safer. The data is encrypted by a modern 256-bit AES algorithm (AES-256-CBC by default)

Installation & Setup

  1. Install with npm - mongocrypt will install mongodb automatically after its setup
npm install mongocrypt
  1. Require mongocrypt & connect to your database
const mongocrypt = require('mongocrypt');
const database_url = "mongodb://yourserver:port/yourdatabase";

mongocrypt.db.connect(url).then(err => {
    if(!err) {
      ...
    }
});

Everyone is invited to fork this project and work on it. If you create a pull request and your code is good and useful for this project, it will be merged into mongocrypt. Collaborators are also searched. For future plans have a look at Trello

Usage

The mongocrypt functions are based on the MongoDB SDK functions. The structure is always the same. You can see each equivalent in the list below.

Important before using database functions:

// Be sure you connected to the database
 if(mongocrypt.db.isConnected()){
    // Set the encryption key
    // Important: It has to be a string with the length of 32
        mongocrypt.encryption.set(yourKey);
 }else{
        // have a look at the Installation & Setup section
 }

Standard usage:

The MongoDB JS SDK function compared with the mongocrypt function

  • With MongoDB's SDK: db.collection(collection).function(parameter, callback(err, res))
  • With Mongocrypt: db.collection(collection).function(parameter).then(err)

The parameters of the mongocrypt functions are identical to the common SDK ones. You can find a list of them here. This principle works for all mongocrypt functions except find() and findOne()

// Example how to use find() and findOne()

/* The option objects takes 3 parameters. The sort object a limit number and a filter object.
 All 3 can also be null. 
*/
const query = {pro: true}
const options = {sort: {rank: 1}, limit: 5, filter: {email: true}
}
const canAlsoBeOptions = null;
mongocrypt.collection("users").find(query, options).then(res => {
    if(res){
        console.log("Email: " + res[0].email)
    } else {
        console.log("An error appeared");
    }
})

// findOne() works on a similar way but it only takes a filter as second parameter
mongocrypt.collection("users").findOne(query, {email: true}).then(res => {})

List of all Functions

  • mongocrypt.encryption.setKey(key)
  • mongocrypt.db.connect(url).then(err)
  • mongocrypt.db.isConnected() returns true or false
  • mongocrypt.db.close()
  • mongocrypt.db.collection(collection).insertOne(object).then(err)
  • mongocrypt.db.collection(collection).insertMany(array).then(err)
  • mongocrypt.db.collection(collection).updateOne(query, object).then(err)
  • mongocrypt.db.collection(collection).updateMany(query, object).then(err)
  • mongocrypt.db.collection(collection).findOne(query, filter).then(res)
  • mongocrypt.db.collection(collection).find(query, options).then(res) options descripted above
  • mongocrypt.db.collection(collection).deleteOne(query).then(err)
  • mongocrypt.db.collection(collection).deleteMany(query).then(err)
  • mongocrypt.db.collection(collection).drop(query).then(err)

Common errors / FAQ

  • Error: please connect first to a database with mongocrypt.db.connect(url)
  • Solution: Look at the setup path of the README. Just fire database functions after the db.connect function has finished

  • Error: please set an encryption key first with mongocrypt.encryption.setKey(key)
  • Solution: Set an encryption key first with encryption.setKey(key)

  • Error: the key has to have a length of 32 characters.
  • Solution: You can only set a string as encryption key with the length of 32 characters.

Do not hesitate to open an issue or send me a message on Twitter

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].