devicely 2.2.3 → 2.2.5
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/encryption.js +88 -0
- package/lib/scriptLoader.js +13 -0
- package/package.json +1 -1
- package/scripts/encrypt-shell-simple.js +4 -21
- package/lib/frontend/static/js/main.223106ce.js +0 -3
- package/lib/frontend/static/js/main.223106ce.js.LICENSE.txt +0 -48
- package/lib/frontend/static/js/main.31418566.js +0 -3
- package/lib/frontend/static/js/main.31418566.js.LICENSE.txt +0 -48
- package/lib/frontend/static/js/main.a507b3fc.js +0 -3
- package/lib/frontend/static/js/main.a507b3fc.js.LICENSE.txt +0 -48
- package/lib/frontend/static/js/main.e6f081bf.js +0 -3
- package/lib/frontend/static/js/main.e6f081bf.js.LICENSE.txt +0 -48
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DEVICELY ENCRYPTION CONFIG
|
|
3
|
+
* ===========================
|
|
4
|
+
* This is the SINGLE SOURCE OF TRUTH for all encryption/decryption
|
|
5
|
+
* Both encrypt-shell-simple.js and scriptLoader.js MUST use this
|
|
6
|
+
*
|
|
7
|
+
* DO NOT modify encryption logic anywhere else!
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const crypto = require('crypto');
|
|
11
|
+
|
|
12
|
+
const ENCRYPTION_CONFIG = {
|
|
13
|
+
algorithm: 'aes-256-cbc',
|
|
14
|
+
encoding: {
|
|
15
|
+
input: 'utf8',
|
|
16
|
+
output: 'hex'
|
|
17
|
+
},
|
|
18
|
+
keyDerivation: 'sha256',
|
|
19
|
+
keySeed: 'devicely-encryption-key-v1'
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Generate encryption key
|
|
24
|
+
* Uses package name + seed for consistency
|
|
25
|
+
*/
|
|
26
|
+
function generateKey() {
|
|
27
|
+
// Try to load package.json from multiple locations
|
|
28
|
+
let packageName = 'devicely';
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
// Try npm-package location
|
|
32
|
+
const pkg = require('../package.json');
|
|
33
|
+
packageName = pkg.name;
|
|
34
|
+
} catch (e1) {
|
|
35
|
+
try {
|
|
36
|
+
// Try dist location
|
|
37
|
+
const pkg = require('../../package.json');
|
|
38
|
+
packageName = pkg.name;
|
|
39
|
+
} catch (e2) {
|
|
40
|
+
// Use default
|
|
41
|
+
packageName = 'devicely';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const keySource = packageName + ENCRYPTION_CONFIG.keySeed;
|
|
46
|
+
return crypto.createHash(ENCRYPTION_CONFIG.keyDerivation).update(keySource).digest();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Encrypt content
|
|
51
|
+
*/
|
|
52
|
+
function encrypt(content) {
|
|
53
|
+
const key = generateKey();
|
|
54
|
+
const iv = crypto.randomBytes(16);
|
|
55
|
+
const cipher = crypto.createCipheriv(ENCRYPTION_CONFIG.algorithm, key, iv);
|
|
56
|
+
|
|
57
|
+
let encrypted = cipher.update(content, ENCRYPTION_CONFIG.encoding.input, ENCRYPTION_CONFIG.encoding.output);
|
|
58
|
+
encrypted += cipher.final(ENCRYPTION_CONFIG.encoding.output);
|
|
59
|
+
|
|
60
|
+
// Return as JSON for clarity and consistency
|
|
61
|
+
return JSON.stringify({
|
|
62
|
+
iv: iv.toString(ENCRYPTION_CONFIG.encoding.output),
|
|
63
|
+
content: encrypted
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Decrypt content
|
|
69
|
+
*/
|
|
70
|
+
function decrypt(encryptedData) {
|
|
71
|
+
const key = generateKey();
|
|
72
|
+
const { iv, content } = JSON.parse(encryptedData);
|
|
73
|
+
|
|
74
|
+
const ivBuffer = Buffer.from(iv, ENCRYPTION_CONFIG.encoding.output);
|
|
75
|
+
const decipher = crypto.createDecipheriv(ENCRYPTION_CONFIG.algorithm, key, ivBuffer);
|
|
76
|
+
|
|
77
|
+
let decrypted = decipher.update(content, ENCRYPTION_CONFIG.encoding.output, ENCRYPTION_CONFIG.encoding.input);
|
|
78
|
+
decrypted += decipher.final(ENCRYPTION_CONFIG.encoding.input);
|
|
79
|
+
|
|
80
|
+
return decrypted;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = {
|
|
84
|
+
ENCRYPTION_CONFIG,
|
|
85
|
+
generateKey,
|
|
86
|
+
encrypt,
|
|
87
|
+
decrypt
|
|
88
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const { decrypt } = require('./encryption');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Decrypt encrypted shell script
|
|
6
|
+
* Uses centralized encryption config for consistency
|
|
7
|
+
*/
|
|
8
|
+
function decryptScript(encryptedFilePath) {
|
|
9
|
+
const encryptedData = fs.readFileSync(encryptedFilePath, 'utf8');
|
|
10
|
+
return decrypt(encryptedData);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = { decryptScript };
|
package/package.json
CHANGED
|
@@ -2,36 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Simple Shell Script Encryption
|
|
5
|
-
*
|
|
5
|
+
* Uses centralized encryption config for consistency
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const fs = require('fs');
|
|
9
9
|
const path = require('path');
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
// Generate encryption key
|
|
13
|
-
function generateKey() {
|
|
14
|
-
const pkg = require('../package.json');
|
|
15
|
-
// Use only package name for consistent key across versions
|
|
16
|
-
return crypto.createHash('sha256').update(pkg.name + 'devicely-encryption-key-v1').digest();
|
|
17
|
-
}
|
|
10
|
+
const { encrypt } = require('../lib/encryption');
|
|
18
11
|
|
|
19
12
|
// Encrypt a file
|
|
20
13
|
function encryptFile(inputPath, outputPath) {
|
|
21
14
|
const content = fs.readFileSync(inputPath, 'utf8');
|
|
22
|
-
const
|
|
23
|
-
const iv = crypto.randomBytes(16);
|
|
24
|
-
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
|
|
25
|
-
|
|
26
|
-
let encrypted = cipher.update(content, 'utf8', 'hex');
|
|
27
|
-
encrypted += cipher.final('hex');
|
|
28
|
-
|
|
29
|
-
const data = JSON.stringify({
|
|
30
|
-
iv: iv.toString('hex'),
|
|
31
|
-
content: encrypted
|
|
32
|
-
});
|
|
15
|
+
const encryptedData = encrypt(content);
|
|
33
16
|
|
|
34
|
-
fs.writeFileSync(outputPath,
|
|
17
|
+
fs.writeFileSync(outputPath, encryptedData);
|
|
35
18
|
console.log(` ✓ ${path.basename(inputPath)} → ${path.basename(outputPath)}`);
|
|
36
19
|
}
|
|
37
20
|
|