You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-13Lines changed: 15 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ A simple symmetric encryption plugin for individual fields. The goal of this plu
6
6
7
7
As of the stable 1.0.0 release, this plugin works on individual fields of any type. However, note that for non-string fields, the original value is set to undefined after encryption. This is because if the schema has defined a field as an array, it would not be possible to replace it with a string value.
8
8
9
-
Also consider [mongoose-encryption](https://github.com/joegoldbeck/mongoose-encryption) if you have other requirements.
9
+
Also consider [mongoose-encryption](https://github.com/joegoldbeck/mongoose-encryption) if you are looking to encrypt the entire document.
10
10
11
11
## How it works
12
12
@@ -24,18 +24,23 @@ Fields which are either objects or of a different type are converted to strings
24
24
25
25
`npm install mongoose-field-encryption`
26
26
27
-
## Usage
27
+
## Security Notes
28
+
29
+
-_Always store your keys and secrets outside of version control and separate from your database._ An environment variable on your application server works well for this.
30
+
- Additionally, store your encryption key offline somewhere safe. If you lose it, there is no way to retrieve your encrypted data.
31
+
- Encrypting passwords is no substitute for appropriately hashing them. `bcrypt` is one great option. You can also encrypt the password afer hashing it although it is not necessary.
32
+
- If an attacker gains access to your application server, they likely have access to both the database and the key. At that point, neither encryption nor authentication do you any good.
28
33
29
-
Keep your secret a secret. Ideally it should only live as an environment variable but definitely not stored anywhere in your repository.
The resulting documents will have the following format:
@@ -70,10 +75,7 @@ From the mongoose package documentation: _Note that findAndUpdate/Remove do not
70
75
Note that as of `1.2.0` release, support for `findOneAndUpdate` has also been added. Note that you would need to specifically set the encryption field marker for it to be encrypted. For example:
- Use `cipheriv` instead of plain `cipher`, [#17](https://github.com/wheresvic/mongoose-field-encryption/issues/17).
125
-
127
+
126
128
Note that this might break any _fixed_ search capability as the encrypted values are now based on a random salt.
127
-
129
+
128
130
Also note that while this version maintains backward compatibility, i.e. decryption will automatically fall back to using the `aes-256-ctr` algorithm, any further updates will lead to the value being encrypted with the salt. In order to fully maintain backwards compatibilty, an new option `useAes256Ctr` has been introduced (default `false`), which can be set to `true` to continue using the plugin as before. It is highly recommended to start using the newer algorithm however, see issue for more details.
0 commit comments