ncrypt-js 2.1.0 → 2.1.2

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.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # NcryptJs
2
2
 
3
- [![Build Status](https://travis-ci.com/ajimae/ncrypt-js.svg?branch=master)](https://travis-ci.com/ajimae/ncrypt-js) [![Coverage Status](https://coveralls.io/repos/github/ajimae/ncrypt-js/badge.svg)](https://coveralls.io/github/ajimae/ncrypt-js) [![NPM](https://img.shields.io/npm/l/ncrypt-js)](https://www.npmjs.com/package/ncrypt-js/v/2.0.0#license)
3
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ajimae/ncrypt-js/release.yml) [![Coverage Status](https://coveralls.io/repos/github/ajimae/ncrypt-js/badge.svg)](https://coveralls.io/github/ajimae/ncrypt-js) ![NPM Downloads](https://img.shields.io/npm/dw/ncrypt-js)
4
4
 
5
- [![GitHub release (latest by date)](https://img.shields.io/github/v/release/ajimae/ncrypt-js)](https://github.com/ajimae/ncrypt-js/releases) [![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/ajimae/ncrypt-js)](https://github/languages/code-size/ajimae/ncrypt-js) [![GitHub issues](https://img.shields.io/github/issues/ajimae/ncrypt-js)](https://github.com/ajimae/ncrypt-js/issues)
5
+ [![GitHub release (latest by date)](https://img.shields.io/github/v/release/ajimae/ncrypt-js)](https://github.com/ajimae/ncrypt-js/releases) [![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/ajimae/ncrypt-js)](https://github/languages/code-size/ajimae/ncrypt-js) [![GitHub issues](https://img.shields.io/github/issues/ajimae/ncrypt-js)](https://github.com/ajimae/ncrypt-js/issues) [![NPM](https://img.shields.io/npm/l/ncrypt-js)](https://www.npmjs.com/package/ncrypt-js/v/2.0.0#license)
6
6
 
7
7
  **_NcryptJs_** is a light weight javascript data encryption and decryption library. This library implements the nodejs default crypto functionality as a mid-channel cipher in addition to a simple and elegant custom data encoding and encryption algorithm.
8
8
 
@@ -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
@@ -90,10 +85,10 @@ However, if you are using ECMAScript 5 and older, use the require statement:
90
85
 
91
86
  ### Using randomString method
92
87
 
93
- 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.
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, api keys 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!";
@@ -125,17 +120,17 @@ console.log("Encryption process...");
125
120
  console.log("Plain Text : " + data);
126
121
  console.log("Cipher Text : " + encryptedData);
127
122
 
128
- // decrypted super encrypted string here
123
+ // decrypting the encrypted super sensitive data here
129
124
  var decryptedData = decrypt(encryptedData);
130
125
  console.log("... and then decryption...");
131
126
  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.
@@ -194,17 +189,20 @@ If you are using any sort of environmental key-value store, e.g `.env` and for a
194
189
  KEY='sshhhh this is a super secret key'
195
190
 
196
191
  # used internally to set the `encoding` - ['base64' | 'binary' | 'hex' | 'ucs-2' | 'ucs2' | 'utf16le']
197
- NCRPT_ENC='hex'
192
+ NCRYPT_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 decrypted._
204
+
205
+ _Same goes for encoding, if data was encrypted using `hex` encoding format, decrypting with a `base64` encoding or other encoding format and vise versa will not work_
208
206
 
209
207
  ## Built With
210
208
 
@@ -214,7 +212,7 @@ Written in [TypeScript](https://typscriptlang.org/), built into ECMAScript 5 usi
214
212
 
215
213
  To contribute, simply fork this project, and issue a pull request.
216
214
 
217
- ## Version Management
215
+ ## Versioning
218
216
 
219
217
  We use [SemVer](http://semver.org/) for version management. For the versions available, see the [tags on this repository](https://github.com/ajimae/ncrypt-js/tags).
220
218
 
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;
@@ -91,7 +91,7 @@ class Ncrypt {
91
91
  return decrypted.toString();
92
92
  };
93
93
  this.secret = secret;
94
- // bind public instnace methods
94
+ // bind public instance methods
95
95
  this.encrypt = this.encrypt.bind(this);
96
96
  this.decrypt = this.decrypt.bind(this);
97
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ncrypt-js",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "a light weight javascript data encryption and decryption library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -51,10 +51,6 @@
51
51
  "files": [
52
52
  "dist",
53
53
  "package.json",
54
- "LICENSE",
55
- "tsconfig.json"
56
- ],
57
- "dependencies": {
58
- "crypto": "^1.0.1"
59
- }
54
+ "LICENSE"
55
+ ]
60
56
  }
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2015",
4
- "module": "commonjs",
5
- "lib": ["es2015", "es2016", "dom", "es2017", "es6", "es5"],
6
- "esModuleInterop": true,
7
- "noImplicitAny": true,
8
- "moduleResolution": "node",
9
- "declaration": true,
10
- "sourceMap": false,
11
- "outDir": "dist",
12
- "baseUrl": ".",
13
- "paths": {
14
- "*": ["node_modules/*","src/types/*"]
15
- }
16
- },
17
- "include": [
18
- "src/**/*", "index.ts",
19
- ],
20
- "exclude": [
21
- "test/**/*"
22
- ]
23
- }