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
+22-26Lines changed: 22 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -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
+
importncryptfrom"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'
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);
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._
0 commit comments