divhunt 2.0.1 → 2.0.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/lib/src/divhunt.js +2 -0
- package/lib/src/mixins/crypto.js +38 -0
- package/package.json +1 -1
package/lib/src/divhunt.js
CHANGED
|
@@ -15,6 +15,7 @@ import DivhuntValidate from './mixins/validate.js';
|
|
|
15
15
|
import DivhuntHelper from './mixins/helper.js';
|
|
16
16
|
import DivhuntRoute from './mixins/route.js';
|
|
17
17
|
import DivhuntError from './mixins/error.js';
|
|
18
|
+
import DivhuntCrypto from './mixins/crypto.js';
|
|
18
19
|
|
|
19
20
|
class Divhunt
|
|
20
21
|
{
|
|
@@ -80,5 +81,6 @@ Object.assign(Divhunt.prototype, DivhuntValidate);
|
|
|
80
81
|
Object.assign(Divhunt.prototype, DivhuntHelper);
|
|
81
82
|
Object.assign(Divhunt.prototype, DivhuntRoute);
|
|
82
83
|
Object.assign(Divhunt.prototype, DivhuntError);
|
|
84
|
+
Object.assign(Divhunt.prototype, DivhuntCrypto);
|
|
83
85
|
|
|
84
86
|
export default Divhunt;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
|
|
3
|
+
const DivhuntCrypto =
|
|
4
|
+
{
|
|
5
|
+
Encrypt(data, key)
|
|
6
|
+
{
|
|
7
|
+
const buffer = Buffer.from(key, 'hex');
|
|
8
|
+
const iv = crypto.randomBytes(12);
|
|
9
|
+
const cipher = crypto.createCipheriv('aes-256-gcm', buffer, iv);
|
|
10
|
+
|
|
11
|
+
let encrypted = cipher.update(JSON.stringify(data), 'utf8', 'base64');
|
|
12
|
+
encrypted += cipher.final('base64');
|
|
13
|
+
|
|
14
|
+
const tag = cipher.getAuthTag();
|
|
15
|
+
|
|
16
|
+
return iv.toString('base64') + ':' + encrypted + ':' + tag.toString('base64');
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
Decrypt(ciphertext, key)
|
|
20
|
+
{
|
|
21
|
+
const buffer = Buffer.from(key, 'hex');
|
|
22
|
+
const [ivB64, encryptedB64, tagB64] = ciphertext.split(':');
|
|
23
|
+
|
|
24
|
+
const iv = Buffer.from(ivB64, 'base64');
|
|
25
|
+
const encrypted = Buffer.from(encryptedB64, 'base64');
|
|
26
|
+
const tag = Buffer.from(tagB64, 'base64');
|
|
27
|
+
|
|
28
|
+
const decipher = crypto.createDecipheriv('aes-256-gcm', buffer, iv);
|
|
29
|
+
decipher.setAuthTag(tag);
|
|
30
|
+
|
|
31
|
+
let decrypted = decipher.update(encrypted, null, 'utf8');
|
|
32
|
+
decrypted += decipher.final('utf8');
|
|
33
|
+
|
|
34
|
+
return JSON.parse(decrypted);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default DivhuntCrypto;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "divhunt",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Full-stack isomorphic JavaScript framework built from scratch. One addon abstraction powers databases, servers, commands, pages, directives, queues, and more.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/load.js",
|