{"id":20481522,"url":"https://github.com/utkarshmish/mongoose-plugin-encryptor","last_synced_at":"2026-06-10T09:32:13.033Z","repository":{"id":50477042,"uuid":"495123224","full_name":"UtkarshMish/mongoose-plugin-encryptor","owner":"UtkarshMish","description":"Mongoose Plugin to encrypt and implement client side field encryption","archived":false,"fork":false,"pushed_at":"2023-11-30T23:44:40.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-05T15:51:12.654Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/UtkarshMish.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-22T17:03:11.000Z","updated_at":"2022-05-22T17:06:34.000Z","dependencies_parsed_at":"2025-01-16T04:12:20.373Z","dependency_job_id":"5e6a7e4d-eed0-4744-ab83-171d57d75733","html_url":"https://github.com/UtkarshMish/mongoose-plugin-encryptor","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/UtkarshMish/mongoose-plugin-encryptor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UtkarshMish%2Fmongoose-plugin-encryptor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UtkarshMish%2Fmongoose-plugin-encryptor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UtkarshMish%2Fmongoose-plugin-encryptor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UtkarshMish%2Fmongoose-plugin-encryptor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UtkarshMish","download_url":"https://codeload.github.com/UtkarshMish/mongoose-plugin-encryptor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UtkarshMish%2Fmongoose-plugin-encryptor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34146871,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T16:08:42.821Z","updated_at":"2026-06-10T09:32:13.010Z","avatar_url":"https://github.com/UtkarshMish.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-plugin-encryptor\n\n[![npm version](https://badge.fury.io/js/mongoose-plugin-encryptor.svg)](https://badge.fury.io/js/mongoose-plugin-encryptor) [![GitHub license](https://img.shields.io/github/license/UtkarshMish/mongoose-plugin-encryptor.svg)](https://github.com/UtkarshMish/mongoose-plugin-encryptor/blob/master/LICENSE)\n\nProvides Client Side field encryption to mongoose documents as a plugin to schemas. It depends on the mongodb `mongodb-client-encryption` package.\n\nEncryption and decryption of data happens natively during `save`, `find` and `upate`.\n\n## How it Works\n\nEncryption is performed using `AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic` by default, user can define another random algorithm supported by mongodb-client-encryption i.e `AEAD_AES_256_CBC_HMAC_SHA_512-Random`.\n\nTo encrypt, the fields that are marked are automatically encrypted using `save` or `insert` or `insertMany` and decrypted when using `find`, `findMany`, `findOne`, additionally it provides encrypt and decrypt methods to handle it explicitly.\n\n## Installation\n\n`npm install mongoose-plugin-encryptor`\n\n## Usage\n\n- Generate and store 96 byte random hex as a secret and mention secret in the option.\n- Use `Buffer.from(SECRET,\"hex\")` to set secret in plugin option\n- Mark fields that are encrypted as `encrypted: true` to notify plugin that field is encrypted\n\n### Basic\n\nFields are encrypted when it has property `encrypted:true`, except for `_id`, `__v`, as well as fields having `boolean` or `number` values.\n\n```[javascript]\nconst mongoose = require('mongoose');\nconst {EncryptionPlugin} = require('mongoose-plugin-encryptor');\n\nconst userSchema = new mongoose.Schema({\n    name: {\n      type: String,\n      encrypted: true // to make name as Encrypted Field\n    },\n    age: {\n      type: Number,\n      required: true\n    }\n    // ... other properties\n});\n\n\nuserSchema.plugin(EncryptionPlugin, {\n  secret: Buffer.from(process.env.SECRET,\"hex\"), // set it in environment variable as hex string\n\n  algorithm: \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\", // algorithm for encrypting field\n\n  keyAltName: \"encryption_key\", // name of the key\n\n  keyVaultNamespace: \"encryption.__keyVault\", // dbname.collection to store encryption keys\n\n });\n\nUser = mongoose.model('User', userSchema);\n\n```\n\nAnd you're all set for it to use. `find`,`findOne`, `findById`, works natively as well as `save` and `update` also works as normal.\n\n### Nested Fields\n\nNested fields are automatically encrypted if the object is marked to be encrypted\n\n## How to Run Unit Tests\n\n1. Install dependencies with `npm install`\n2. Start mongo with `mongod`\n3. Run tests with `npm test`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futkarshmish%2Fmongoose-plugin-encryptor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Futkarshmish%2Fmongoose-plugin-encryptor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futkarshmish%2Fmongoose-plugin-encryptor/lists"}