ncrypt-js 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +22 -26
  2. package/dist/index.js +1 -0
  3. package/package.json +2 -5
package/README.md CHANGED
@@ -16,7 +16,8 @@
16
16
  * [NcryptJs Methods](#ncryptjs-methods)
17
17
  * [Using the `randomString()` methods](#using-randomstring-method)
18
18
  * [Using `encrypt()` and `decrypt()` methods](#using-encrypt-and-decrypt-methods)
19
- * [Using default imports](#using-default-imports)
19
+ * [Stirng Encryption](#string-encryption)
20
+ * [Object Encryption](#object-encryption)
20
21
  * [Built With](#built-with)
21
22
  * [Contribution](#contribution)
22
23
  * [Version Management](#version-management)
@@ -51,23 +52,17 @@ yarn add ncrypt-js
51
52
 
52
53
  To include **_ncrypt-js_** in your project. use one of these:
53
54
 
54
- ```diff
55
+ ```js
55
56
  // ES6 and later
56
- + import ncrypt from "ncrypt-js";
57
- - import * as ncrypt from "ncrypt-js";
58
-
59
- // or
60
- - import { encrypt, decrypt } from "ncrypt-js";
57
+ import ncrypt from "ncrypt-js";
58
+ // or import { ncrypt } from "ncrypt-js"
61
59
  ```
62
60
 
63
61
  However, if you are using ECMAScript 5 and older, use the require statement:
64
62
 
65
- ```diff
63
+ ```js
66
64
  // ES5 and older
67
- + var ncrypt = require("ncrypt-js");
68
-
69
- // or
70
- - var { encrypt, decrypt } = require("ncrypt-js");
65
+ var { ncrypt } = require("ncrypt-js");
71
66
  ```
72
67
 
73
68
  ## Documentation
@@ -93,7 +88,7 @@ However, if you are using ECMAScript 5 and older, use the require statement:
93
88
  The `randomString()` static method can generate [random bytes](https://nodejs.org/api/crypto.html#cryptorandombytessize-callback) encoded into a `hexadecimal` or `base64` strings. This string can be useful in a variety of use cases e.g to generate database ids, to generate a unique string for a list, a unique serial strings etc.
94
89
 
95
90
  ```ts
96
- var ncrypt = require('ncrypt-js');
91
+ var { ncrypt } = require('ncrypt-js'); // or import ncrypt from 'ncrypt-js'
97
92
 
98
93
  var randomStr = ncrypt.randomString(8, 'base64');
99
94
  console.log(randomStr) // t78WcmYAFOY=
@@ -103,13 +98,13 @@ ncrypt.randomString(size?: number, enc?: 'base64' | 'hex');
103
98
  ```
104
99
 
105
100
  ### Using encrypt() and decrypt() methods
106
- The `encrypt()` and `decrypt()` methods as of version 2.0.0 directly importing or invoking these methods is deprecated, an object must be created with a secret first, before the methods can now be invoked on the created object.
101
+ The `encrypt()` and `decrypt()` methods as of version 2.0.0 directly importing or invoking these methods is `deprecated`, an object must first be created with a secret, before the methods can then be invoked on the created object.
107
102
 
108
103
  To `encrypt` and `decrypt` data, simply use `encrypt()` and `decrypt()` methods respectively. This will use `AES-256-CBC` encryption algorithm as the mid-channel cipher.
109
104
 
110
105
  ```diff
111
106
  - var { encrypt, decrypt } = require("ncrypt-js");
112
- + var ncrypt = require("ncrypt-js");
107
+ + var { ncrypt } = require("ncrypt-js");
113
108
 
114
109
 
115
110
  var data = "Hello World!";
@@ -132,10 +127,10 @@ console.log("Decipher Text : " + decryptedData);
132
127
  console.log("...done.");
133
128
  ```
134
129
 
135
- ### Using default imports
130
+ ### String Encryption
136
131
 
137
132
  ```javascript
138
- var ncrypt = require("ncrypt-js");
133
+ var { ncrypt } = require("ncrypt-js");
139
134
 
140
135
  var data = "Hello World!";
141
136
  var _secretKey = "some-super-secret-key";
@@ -148,7 +143,7 @@ console.log("Encryption process...");
148
143
  console.log("Plain Text : " + data);
149
144
  console.log("Cipher Text : " + encryptedData);
150
145
 
151
- // decrypted super encrypted string here
146
+ // decrypted super encrypted data here
152
147
  var decryptedData = ncryptObject.decrypt(encryptedData);
153
148
  console.log("... and then decryption...");
154
149
  console.log("Decipher Text : " + decryptedData);
@@ -163,7 +158,7 @@ To encrypt and decrypt JavaScript object literal, simply use `encrypt()` and `de
163
158
 
164
159
 
165
160
  ```javascript
166
- var ncrypt = require("ncrypt-js");
161
+ var { ncrypt } = require("ncrypt-js");
167
162
 
168
163
  var _secretKey = "some-super-secret-key";
169
164
  var object = {
@@ -176,13 +171,13 @@ var ncryptObject = new ncrypt('ncrypt-js');
176
171
  // encrypting super sensitive data here
177
172
  var encryptedObject = ncryptObject.encrypt(object);
178
173
  console.log("Encryption process...");
179
- console.log("Plain Object : " + object);
174
+ console.log("Plain Object : ", object);
180
175
  console.log("Encrypted Object : " + encryptedObject);
181
176
 
182
- // decrypted super encrypted string here
177
+ // decrypted super sensitive data here
183
178
  var decryptedObject = ncryptObject.decrypt(encryptedObject);
184
179
  console.log("... and then decryption...");
185
- console.log("Decipher Text : " + decryptedObject);
180
+ console.log("Decipher Text : ", decryptedObject);
186
181
  console.log("...done.");
187
182
  ````
188
183
  If you are using any sort of environmental key-value store, e.g `.env` and for additional security, you can add the following to your environment.
@@ -198,13 +193,14 @@ NCRPT_ENC='hex'
198
193
 
199
194
  SECRET='this is our hashing secret'
200
195
  ```
201
- Then when creating your object, you can use the SECRET from your environment e.g:
202
- ```
203
- ...
204
- var ncrypt = require('ncrypt-js');
196
+ When creating your object, you can use the `SECRET` from your environment e.g:
197
+
198
+ ```js
199
+ var { ncrypt } = require('ncrypt-js');
205
200
  var { encrypt, decrypt } = new ncrypt(process.env.SECRET);
206
201
  ...
207
202
  ```
203
+ _**NOTE:** The secret is required to decrypt the encrypted data, if the secret used to encrypt a specific data is lost, then that data cannot be decripted._
208
204
 
209
205
  ## Built With
210
206
 
package/dist/index.js CHANGED
@@ -6,4 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const ncrypt_1 = __importDefault(require("./src/ncrypt"));
7
7
  exports.ncrypt = ncrypt_1.default;
8
8
  module.exports = ncrypt_1.default;
9
+ module.exports.ncrypt = ncrypt_1.default;
9
10
  exports.default = ncrypt_1.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ncrypt-js",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "a light weight javascript data encryption and decryption library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -53,8 +53,5 @@
53
53
  "package.json",
54
54
  "LICENSE",
55
55
  "tsconfig.json"
56
- ],
57
- "dependencies": {
58
- "crypto": "^1.0.1"
59
- }
56
+ ]
60
57
  }