Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ipbyrne/mongo-encrypted-query

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ipbyrne/mongo-encrypted-query - npm Package Compare versions

Comparing version 0.0.9 to 1.0.0

2

package.json

@@ -6,3 +6,3 @@ {

"license": "Apache-2.0",
"version": "0.0.9",
"version": "1.0.0",
"main": "dist/index.js",

@@ -9,0 +9,0 @@ "typings": "dist/index.d.ts",

@@ -16,2 +16,6 @@ # Mongo Encrypted Query

### Encrypt Data (`encryptData`)
Parameters:
- Data: This is the data you want to encrypt.
- Private Key JWK: This is the key you want to use for encryption
This function is to be used whenever you are saving data into the database. You are expected to pass into this function the data to be saved and the private key you are going to use to encrypt the data to make the data queryable.

@@ -21,6 +25,19 @@

Once encrypted you can save the data as is, or under any key value like `data` or something similiar. If you do save the data under a key value, you MUST pass that key to the `encryptQuery` function in order for the query to work.
### Encrypt Query (`encryptQuery`)
Parameters:
- Query: This is a MongoDB query written as if the data was not encrypted.
- Private Key JWK: This is the key you used to encrypt the data you saved to MongoDB.
- Prefix: This is the key the data is saved under. If you are saving the data to MongoDB as it comes out of `encryptData` you do not need to provide this parameter.
This function is to be used to format any query you want to use when querying the database. This function takes in the traditional MongoDB query, along with the private key used when saving the data you are trying to query.
As mentioned above, if you save your encrypted data under a specific key value (like `data`), you must pass this key to the `encryptQuery` function in order for the returned query to work.
### Decrypt Data (`decryptData`)
Parameters:
- Data: This is the encrypted data you are trying to decrypt.
- Private Key JWK: This is the key you used to encrypt the data you saved to MongoDB.
This function is used to decrypt the data returned from MongoDB. This function is expecting the data returned from MongoDB, the private key you will use to decrypt the data.

@@ -27,0 +44,0 @@

@@ -10,5 +10,16 @@ import {

export const encryptQuery = (query: any, privateKeyJwk: PrivateKeyJwk) => {
const hashedQuery = createEntrypedQuery(query, privateKeyJwk);
return hashedQuery;
export const encryptQuery = (
query: any,
privateKeyJwk: PrivateKeyJwk,
prefix?: string
) => {
const encryptedQuery = createEntrypedQuery(query, privateKeyJwk);
if (prefix) {
const prefixedEncryptedQuery: any = {};
Object.keys(encryptedQuery).forEach((key: string) => {
prefixedEncryptedQuery[`${prefix}.${key}`] = encryptedQuery[key];
});
return prefixedEncryptedQuery;
}
return encryptedQuery;
};

@@ -15,0 +26,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc