Skip to content

Commit d697fd8

Browse files
committed
Package renamed
1 parent c3f3cc1 commit d697fd8

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

README.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
# [**@tsmx/mongoose-encryptedstring**](https://github.com/tsmx/mongoose-encryptedstring)
1+
# [**@tsmx/mongoose-encrypted-string**](https://github.com/tsmx/mongoose-encrypted-string)
22

33
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4-
![npm (scoped)](https://img.shields.io/npm/v/@tsmx/mongoose-encryptedstring)
5-
![node-current (scoped)](https://img.shields.io/node/v/@tsmx/mongoose-encryptedstring)
6-
[![Build Status](https://travis-ci.com/tsmx/mongoose-encryptedstring.svg?branch=master)](https://travis-ci.org/tsmx/mongoose-encryptedstring)
7-
[![Coverage Status](https://coveralls.io/repos/github/tsmx/mongoose-encryptedstring/badge.svg?branch=master)](https://coveralls.io/github/tsmx/mongoose-encryptedstring?branch=master)
4+
![npm (scoped)](https://img.shields.io/npm/v/@tsmx/mongoose-encrypted-string)
5+
![node-current (scoped)](https://img.shields.io/node/v/@tsmx/mongoose-encrypted-string)
6+
[![Build Status](https://travis-ci.com/tsmx/mongoose-encrypted-string.svg?branch=master)](https://travis-ci.org/tsmx/mongoose-encrypted-string)
7+
[![Coverage Status](https://coveralls.io/repos/github/tsmx/mongoose-encrypted-string/badge.svg?branch=master)](https://coveralls.io/github/tsmx/mongoose-encrypted-string?branch=master)
88

9-
> `EncryptedString` type for Mongoose schemas.
10-
11-
AES-256-CBC encryption-at-rest for strings.
9+
> `EncryptedString` type for Mongoose schemas. Provides AES-256-CBC encryption-at-rest for strings.
1210
1311
## Usage
1412

1513
```js
1614
var mongoose = require('mongoose');
17-
const encryptedString = require('@tsmx/mongoose-encryptedstring');
15+
const mes = require('@tsmx/mongoose-encrypted-string');
1816
const key = 'YOUR KEY HERE';
1917

2018
// register the new type EncryptedString
21-
encryptedString.registerEncryptedString(mongoose, key);
19+
mes.registerEncryptedString(mongoose, key);
2220

2321
// use EncryptedString in your schemas
2422
Person = mongoose.model('Person', {
@@ -64,6 +62,24 @@ The mongoose instance where `EncryptedString` should be registered.
6462

6563
The key used for encryption/decryption. Length must be 32 bytes. See [notes](#notes) for details.
6664

65+
## Use with lean() queries
66+
67+
For performance reasons it maybe useful to use Mongoose's `lean()` queries. Doing so, the query will return the raw JSON objects from the MongoDB database where all properties of type `EncryptedString` are encrypted.
68+
69+
To get the clear text values back you can directly use [@tsmx/string-crypto](https://www.npmjs.com/package/@tsmx/string-crypto) which is also used internally in this package for encryption and decryption.
70+
71+
```js
72+
const key = 'YOUR KEY HERE';
73+
const sc = require('@tsmx/string-crypto');
74+
75+
// query raw objects with encrypted string values
76+
let person = await Person.findOne({ id: 'id-test' }).lean();
77+
78+
// decrypt using string-crypto
79+
let firstName = sc.decrypt(person.firstName, { key: key });
80+
let lastName = sc.decrypt(person.lastName, { key: key });
81+
```
82+
6783
## Notes
6884

6985
- Encryption/decryption is done via the package [@tsmx/string-crypto](https://www.npmjs.com/package/@tsmx/string-crypto).
File renamed without changes.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "@tsmx/mongoose-encryptedstring",
2+
"name": "@tsmx/mongoose-encrypted-string",
33
"version": "1.0.0",
44
"description": "EncryptedString type for Mongoose schemas.",
5-
"main": "mongoose-encryptedstring.js",
5+
"main": "mongoose-encrypted-string.js",
66
"engines": {
77
"node": ">=12.0.0",
88
"npm": ">=6.0.0"
@@ -16,7 +16,7 @@
1616
"license": "MIT",
1717
"repository": {
1818
"type": "git",
19-
"url": "https://github.com/tsmx/mongoose-encryptedstring.git"
19+
"url": "https://github.com/tsmx/mongoose-encrypted-string.git"
2020
},
2121
"keywords": [
2222
"mongoose",

test/mongoose-encryptedstring.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const mongoose = require('mongoose');
22
const sc = require('@tsmx/string-crypto');
33
const MongoMemoryServer = require('mongodb-memory-server').MongoMemoryServer;
4-
const mes = require('../mongoose-encryptedstring');
4+
const mes = require('../mongoose-encrypted-string');
55

6-
describe('mongoose-encryptedstring test suite', () => {
6+
describe('mongoose-encrypted-string test suite', () => {
77

88
const testKey = '9af7d400be4705147dc724db25bfd2513aa11d6013d7bf7bdb2bfe050593bd0f';
99

0 commit comments

Comments
 (0)