k9crypt 1.0.6 → 1.0.8
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 +12 -0
- package/package.json +1 -1
- package/src/index.js +8 -5
- package/src/utils/encryption.js +26 -5
package/README.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
This is a special encryption algorithm created for K9Crypt.
|
|
4
4
|
|
|
5
|
+
## Updates
|
|
6
|
+
**v1.0.8**
|
|
7
|
+
- Enhanced encryption security with 5-layer encryption system
|
|
8
|
+
- Added multiple AES encryption modes in sequence:
|
|
9
|
+
- AES-256-GCM
|
|
10
|
+
- AES-256-CBC
|
|
11
|
+
- AES-256-CFB
|
|
12
|
+
- AES-256-OFB
|
|
13
|
+
- AES-256-CTR
|
|
14
|
+
- Each layer now uses its own initialization vector (IV)
|
|
15
|
+
- Improved data integrity with comprehensive authentication
|
|
16
|
+
|
|
5
17
|
## Installation
|
|
6
18
|
|
|
7
19
|
```bash
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -15,10 +15,10 @@ class K9crypt {
|
|
|
15
15
|
const compressed = await compress(plaintext);
|
|
16
16
|
const salt = crypto.randomBytes(SALT_SIZE);
|
|
17
17
|
const key = await deriveKey(this.secretKey, salt);
|
|
18
|
-
const { iv1, iv2, encrypted, tag1 } = encrypt(compressed, key);
|
|
19
|
-
const dataToHash = Buffer.concat([salt, iv1, iv2, encrypted, tag1]);
|
|
18
|
+
const { iv1, iv2, iv3, iv4, iv5, encrypted, tag1 } = encrypt(compressed, key);
|
|
19
|
+
const dataToHash = Buffer.concat([salt, iv1, iv2, iv3, iv4, iv5, encrypted, tag1]);
|
|
20
20
|
const dataHash = hash(dataToHash);
|
|
21
|
-
const result = Buffer.concat([salt, iv1, iv2, encrypted, tag1, dataHash]);
|
|
21
|
+
const result = Buffer.concat([salt, iv1, iv2, iv3, iv4, iv5, encrypted, tag1, dataHash]);
|
|
22
22
|
return result.toString('base64');
|
|
23
23
|
} catch (error) {
|
|
24
24
|
console.log('Encryption failed');
|
|
@@ -31,7 +31,10 @@ class K9crypt {
|
|
|
31
31
|
const salt = data.slice(0, SALT_SIZE);
|
|
32
32
|
const iv1 = data.slice(SALT_SIZE, SALT_SIZE + IV_SIZE);
|
|
33
33
|
const iv2 = data.slice(SALT_SIZE + IV_SIZE, SALT_SIZE + 2 * IV_SIZE);
|
|
34
|
-
const
|
|
34
|
+
const iv3 = data.slice(SALT_SIZE + 2 * IV_SIZE, SALT_SIZE + 3 * IV_SIZE);
|
|
35
|
+
const iv4 = data.slice(SALT_SIZE + 3 * IV_SIZE, SALT_SIZE + 4 * IV_SIZE);
|
|
36
|
+
const iv5 = data.slice(SALT_SIZE + 4 * IV_SIZE, SALT_SIZE + 5 * IV_SIZE);
|
|
37
|
+
const encrypted = data.slice(SALT_SIZE + 5 * IV_SIZE, -TAG_SIZE - 64);
|
|
35
38
|
const tag1 = data.slice(-TAG_SIZE - 64, -64);
|
|
36
39
|
const dataHash = data.slice(-64);
|
|
37
40
|
|
|
@@ -41,7 +44,7 @@ class K9crypt {
|
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
const key = await deriveKey(this.secretKey, salt);
|
|
44
|
-
const decrypted = decrypt(encrypted, key, iv1, iv2, tag1);
|
|
47
|
+
const decrypted = decrypt(encrypted, key, iv1, iv2, iv3, iv4, iv5, tag1);
|
|
45
48
|
const decompressed = await decompress(decrypted);
|
|
46
49
|
return decompressed.toString('utf8');
|
|
47
50
|
} catch (error) {
|
package/src/utils/encryption.js
CHANGED
|
@@ -12,15 +12,36 @@ exports.encrypt = (data, key) => {
|
|
|
12
12
|
const cipher2 = crypto.createCipheriv('aes-256-cbc', key, iv2);
|
|
13
13
|
let encrypted2 = cipher2.update(encrypted1);
|
|
14
14
|
encrypted2 = Buffer.concat([encrypted2, cipher2.final()]);
|
|
15
|
-
const
|
|
15
|
+
const iv3 = crypto.randomBytes(IV_SIZE);
|
|
16
|
+
const cipher3 = crypto.createCipheriv('aes-256-cfb', key, iv3);
|
|
17
|
+
let encrypted3 = cipher3.update(encrypted2);
|
|
18
|
+
encrypted3 = Buffer.concat([encrypted3, cipher3.final()]);
|
|
19
|
+
const iv4 = crypto.randomBytes(IV_SIZE);
|
|
20
|
+
const cipher4 = crypto.createCipheriv('aes-256-ofb', key, iv4);
|
|
21
|
+
let encrypted4 = cipher4.update(encrypted3);
|
|
22
|
+
encrypted4 = Buffer.concat([encrypted4, cipher4.final()]);
|
|
23
|
+
const iv5 = crypto.randomBytes(IV_SIZE);
|
|
24
|
+
const cipher5 = crypto.createCipheriv('aes-256-ctr', key, iv5);
|
|
25
|
+
let encrypted5 = cipher5.update(encrypted4);
|
|
26
|
+
encrypted5 = Buffer.concat([encrypted5, cipher5.final()]);
|
|
27
|
+
const permutedEncrypted = reverseBuffer(encrypted5);
|
|
16
28
|
|
|
17
|
-
return { iv1, iv2, encrypted: permutedEncrypted, tag1 };
|
|
29
|
+
return { iv1, iv2, iv3, iv4, iv5, encrypted: permutedEncrypted, tag1 };
|
|
18
30
|
};
|
|
19
31
|
|
|
20
|
-
exports.decrypt = (encrypted, key, iv1, iv2, tag1) => {
|
|
32
|
+
exports.decrypt = (encrypted, key, iv1, iv2, iv3, iv4, iv5, tag1) => {
|
|
21
33
|
const originalEncrypted = reverseBuffer(encrypted, true);
|
|
34
|
+
const decipher5 = crypto.createDecipheriv('aes-256-ctr', key, iv5);
|
|
35
|
+
let decrypted5 = decipher5.update(originalEncrypted);
|
|
36
|
+
decrypted5 = Buffer.concat([decrypted5, decipher5.final()]);
|
|
37
|
+
const decipher4 = crypto.createDecipheriv('aes-256-ofb', key, iv4);
|
|
38
|
+
let decrypted4 = decipher4.update(decrypted5);
|
|
39
|
+
decrypted4 = Buffer.concat([decrypted4, decipher4.final()]);
|
|
40
|
+
const decipher3 = crypto.createDecipheriv('aes-256-cfb', key, iv3);
|
|
41
|
+
let decrypted3 = decipher3.update(decrypted4);
|
|
42
|
+
decrypted3 = Buffer.concat([decrypted3, decipher3.final()]);
|
|
22
43
|
const decipher2 = crypto.createDecipheriv('aes-256-cbc', key, iv2);
|
|
23
|
-
let decrypted2 = decipher2.update(
|
|
44
|
+
let decrypted2 = decipher2.update(decrypted3);
|
|
24
45
|
decrypted2 = Buffer.concat([decrypted2, decipher2.final()]);
|
|
25
46
|
const decipher1 = crypto.createDecipheriv('aes-256-gcm', key, iv1);
|
|
26
47
|
decipher1.setAuthTag(tag1);
|
|
@@ -28,4 +49,4 @@ exports.decrypt = (encrypted, key, iv1, iv2, tag1) => {
|
|
|
28
49
|
decrypted1 = Buffer.concat([decrypted1, decipher1.final()]);
|
|
29
50
|
|
|
30
51
|
return decrypted1;
|
|
31
|
-
};
|
|
52
|
+
};
|