{"id":14975635,"url":"https://github.com/jsdream/mongoose-advanced-encryption","last_synced_at":"2025-10-27T14:30:43.142Z","repository":{"id":30862700,"uuid":"126226043","full_name":"jsdream/mongoose-advanced-encryption","owner":"jsdream","description":"Mongoose plugin for document fields encryption and authentication preserving ability to query for encrypted fields.","archived":false,"fork":false,"pushed_at":"2022-12-30T21:33:54.000Z","size":109,"stargazers_count":4,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T06:11:22.901Z","etag":null,"topics":["aes-256","authentication","encrypted-fields","encryption","mongodb","mongoose","mongoose-plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsdream.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-21T18:50:46.000Z","updated_at":"2022-10-03T13:31:50.000Z","dependencies_parsed_at":"2023-01-14T18:00:33.997Z","dependency_job_id":null,"html_url":"https://github.com/jsdream/mongoose-advanced-encryption","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsdream%2Fmongoose-advanced-encryption","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsdream%2Fmongoose-advanced-encryption/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsdream%2Fmongoose-advanced-encryption/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsdream%2Fmongoose-advanced-encryption/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsdream","download_url":"https://codeload.github.com/jsdream/mongoose-advanced-encryption/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238508529,"owners_count":19484149,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["aes-256","authentication","encrypted-fields","encryption","mongodb","mongoose","mongoose-plugin"],"created_at":"2024-09-24T13:52:19.059Z","updated_at":"2025-10-27T14:30:37.820Z","avatar_url":"https://github.com/jsdream.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-advanced-encryption\n\nMongoose plugin for document fields encryption and authentication preserving ability to query for encrypted field.\n\n## Overview\n\nThis plugin provides encryption, hashing (blind indexing) and authentication for Mongoose document fields.\nFields encryption is performed using `AES-256-CBC` algorithm, hashing as well as authentication using `HMAC-SHA-512`.\n\n## Requirements\n\n\n\n## Defining field encryption settings\nThe plugin works on per-field encryption basis. To mark field to be encrypted it is necessary to specify it's encryption\noptions using `encrypt` option on it's SchemaType definition. The `encrypt` option can be either a `boolean` \n(e.g. `true` will enable encryption of the field, `false` is the same as not setting the option at all) or an `Object`\nwith field's encryption settings, which would override defaults. It is possible to specify default `encrypt` options\non schema level as `encrypt` field on plugin options. \nIf it's not specified plugin's [hard-coded config](#default-plugin-configuration-is-the-following) will be used.\n\n## Getting Started\n\n`npm install mongoose-advanced-encryption --save`\n\n###### Generate encryption keys:\n`openssl rand -base64 32; openssl rand -base64 64; openssl rand -base64 64;`\n\n\n## Plugin Options\n\n- `encryptionKey` - a 32-byte base64 string.\n- `hashingKey` - a 64-byte base64 string.\n- `authenticationKey` - a 64-byte base64 string.\n- `decryptAfterSave` - Enables automatic documents decryption passed to `doc.save()` callback.\n- `skipAuthenticationIfNoSignature` - Disables document authentication if document has no signature.\n- `encrypt` - Allows to adjust plugin's default field encryption options on per schema level. \n    These options can be overridden on per field level.  \n    - `hash` - Indicates either hash should be created or not.\n        - `index` - Indicates either index for the hash field should be created of not.\n\n###### Default plugin configuration is the following:\n```js\nconst defaultConfig = {\n    decryptAfterSave: false,\n    encrypt: {\n        hash: { // means that hash will be created, but without MongoDB index\n            index: false\n        }\n    }\n}\n```\n\n## Instance Methods\n\n- `encEncrypt`\n- `encDecrypt`\n- `encSign`\n- `encAuthenticate`\n\n## Supported query methods\nWith the methods below encryption/decryption works transparently.\n- count\n- countDocuments\n- find\n- findOne\n- findOneAndRemove\n- findOneAndUpdate\n- update\n\n## Security Issue Reporting / Disclaimer\n\nI am in no way a security expert. The plugin is a result of deep research on security-related topics,\nbut I do not have any underlying expertise in security. If you wish to use this plugin in your project please \nanalyse the code carefully and use it at your own risk.\n**If you find any security-related issues, please email me at vladyslavmashkin@gmail.com**. \nFor non-security-related issues, feel free to open a Github issue or pull request.   \n\n## Credits\n\nBig thanks to [mongoose-encryption](https://github.com/joegoldbeck/mongoose-encryption) plugin authors for the source of inspiration.\nThe `mongoose-encryption` plugin is great, but since authors decided to keep it simple for security reasons it is not sufficient enough\nfor our use case. That is why a decision to write a more \"advanced\" plugin was made.\n\nAlso another big thanks goes to this [article](https://www.sitepoint.com/how-to-search-on-securely-encrypted-database-fields/) author.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2018 Vladyslav Mashkin\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsdream%2Fmongoose-advanced-encryption","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsdream%2Fmongoose-advanced-encryption","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsdream%2Fmongoose-advanced-encryption/lists"}