k9crypt 1.1.2 → 1.1.4

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
@@ -5,38 +5,72 @@
5
5
  This is a special encryption algorithm created for K9Crypt.
6
6
 
7
7
  ## Updates
8
- **v1.1.2**
9
- - The issue caused by modules has been resolved.
8
+
9
+ **v1.1.4**
10
+
11
+ - You can now use the module in both ES Modules and CommonJS formats. This makes it easier to switch between different module types in your project.
10
12
 
11
13
  ## Installation
12
14
 
13
15
  ```bash
14
- npm install k9crypt
16
+ bun add k9crypt
17
+ # npm install k9crypt
18
+ # pnpm add k9crypt
19
+ # yarn add k9crypt
15
20
  ```
16
21
 
17
22
  ## Usage
18
23
 
24
+ Usage in CommonJS:
19
25
  ```javascript
20
26
  const k9crypt = require('k9crypt');
21
27
 
22
28
  async function test() {
23
- const secretKey = 'VeryLongSecretKey!@#1234567890';
24
- const encryptor = new k9crypt(secretKey);
25
- const plaintext = 'Hello, World!';
26
-
27
- try {
28
- const encrypted = await encryptor.encrypt(plaintext);
29
- console.log('Encrypted data:', encrypted);
30
-
31
- const decrypted = await encryptor.decrypt(encrypted);
32
- console.log('Decrypted data:', decrypted);
33
- } catch (error) {
34
- console.error('Encryption error:', error);
35
- }
29
+ const secretKey = 'VeryLongSecretKey!@#1234567890';
30
+ const encryptor = new k9crypt(secretKey);
31
+ // Or you can use it without providing a secretKey value. A key will be generated by the system.
32
+ // const encryptor = new k9crypt();
33
+ const plaintext = 'Hello, World!';
34
+
35
+ try {
36
+ const encrypted = await encryptor.encrypt(plaintext);
37
+ console.log('Encrypted data:', encrypted);
38
+
39
+ const decrypted = await encryptor.decrypt(encrypted);
40
+ console.log('Decrypted data:', decrypted);
41
+ } catch (error) {
42
+ console.error('Encryption error:', error);
43
+ }
44
+ }
45
+
46
+ test();
47
+ ```
48
+
49
+ Usage in ES Modules:
50
+ ```javascript
51
+ import k9crypt from 'k9crypt';
52
+
53
+ async function test() {
54
+ const secretKey = 'VeryLongSecretKey!@#1234567890';
55
+ const encryptor = new k9crypt(secretKey);
56
+ // Or you can use it without providing a secretKey value. A key will be generated by the system.
57
+ // const encryptor = new k9crypt();
58
+ const plaintext = 'Hello, World!';
59
+
60
+ try {
61
+ const encrypted = await encryptor.encrypt(plaintext);
62
+ console.log('Encrypted data:', encrypted);
63
+
64
+ const decrypted = await encryptor.decrypt(encrypted);
65
+ console.log('Decrypted data:', decrypted);
66
+ } catch (error) {
67
+ console.error('Encryption error:', error);
68
+ }
36
69
  }
37
70
 
38
71
  test();
39
72
  ```
40
73
 
41
74
  ## License
75
+
42
76
  This project is licensed under the MIT license.
@@ -1,3 +1,5 @@
1
+ "use strict";
2
+
1
3
  module.exports = {
2
4
  SALT_SIZE: 32,
3
5
  IV_SIZE: 16,
@@ -6,5 +8,5 @@ module.exports = {
6
8
  PBKDF2_ITERATIONS: 310000,
7
9
  HASH_SEED: 0xCAFEBABE,
8
10
  PEPPER: 'veryLongAndComplexPepperValue123!@#$%^&*()_+[]{}|;:,.<>?',
9
- HMAC_KEY: 'veryLongAndComplexHMACKeyValue456!@#$%^&*()_+[]{}|;:,.<>?',
11
+ HMAC_KEY: 'veryLongAndComplexHMACKeyValue456!@#$%^&*()_+[]{}|;:,.<>?'
10
12
  };
@@ -1,21 +1,53 @@
1
- const crypto = require('crypto');
2
- const { compress, decompress } = require('./utils/compression');
3
- const { deriveKey } = require('./utils/keyDerivation');
4
- const { encrypt, decrypt } = require('./utils/encryption');
5
- const { hash, verifyHash } = require('./utils/hashing');
6
- const { SALT_SIZE, IV_SIZE, TAG_SIZE } = require('./constants');
1
+ "use strict";
7
2
 
3
+ const crypto = require('crypto');
4
+ const {
5
+ compress,
6
+ decompress
7
+ } = require('./utils/compression');
8
+ const {
9
+ deriveKey
10
+ } = require('./utils/keyDerivation');
11
+ const {
12
+ encrypt,
13
+ decrypt
14
+ } = require('./utils/encryption');
15
+ const {
16
+ hash,
17
+ verifyHash
18
+ } = require('./utils/hashing');
19
+ const {
20
+ SALT_SIZE,
21
+ IV_SIZE,
22
+ TAG_SIZE
23
+ } = require('./constants');
8
24
  class K9crypt {
9
25
  constructor(secretKey) {
10
- this.secretKey = secretKey;
26
+ if (!secretKey) {
27
+ this.secretKey = crypto.randomBytes(50);
28
+ this._autoGenerated = true;
29
+ } else {
30
+ this._autoGenerated = false;
31
+ this.secretKey = secretKey;
32
+ }
33
+ }
34
+ getGenerated() {
35
+ return this._autoGenerated ? this.secretKey : null;
11
36
  }
12
-
13
37
  async encrypt(plaintext) {
14
38
  try {
15
39
  const compressed = await compress(plaintext);
16
40
  const salt = crypto.randomBytes(SALT_SIZE);
17
41
  const key = await deriveKey(this.secretKey, salt);
18
- const { iv1, iv2, iv3, iv4, iv5, encrypted, tag1 } = encrypt(compressed, key);
42
+ const {
43
+ iv1,
44
+ iv2,
45
+ iv3,
46
+ iv4,
47
+ iv5,
48
+ encrypted,
49
+ tag1
50
+ } = encrypt(compressed, key);
19
51
  const dataToHash = Buffer.concat([salt, iv1, iv2, iv3, iv4, iv5, encrypted, tag1]);
20
52
  const dataHash = hash(dataToHash);
21
53
  const result = Buffer.concat([salt, iv1, iv2, iv3, iv4, iv5, encrypted, tag1, dataHash]);
@@ -24,7 +56,6 @@ class K9crypt {
24
56
  console.log('Encryption failed');
25
57
  }
26
58
  }
27
-
28
59
  async decrypt(ciphertext) {
29
60
  try {
30
61
  const data = Buffer.from(ciphertext, 'base64');
@@ -37,12 +68,10 @@ class K9crypt {
37
68
  const encrypted = data.slice(SALT_SIZE + 5 * IV_SIZE, -TAG_SIZE - 64);
38
69
  const tag1 = data.slice(-TAG_SIZE - 64, -64);
39
70
  const dataHash = data.slice(-64);
40
-
41
71
  const dataToVerify = data.slice(0, -64);
42
72
  if (!verifyHash(dataToVerify, dataHash)) {
43
73
  console.log('Data integrity check failed');
44
74
  }
45
-
46
75
  const key = await deriveKey(this.secretKey, salt);
47
76
  const decrypted = decrypt(encrypted, key, iv1, iv2, iv3, iv4, iv5, tag1);
48
77
  const decompressed = await decompress(decrypted);
@@ -52,5 +81,4 @@ class K9crypt {
52
81
  }
53
82
  }
54
83
  }
55
-
56
84
  module.exports = K9crypt;
@@ -1,7 +1,8 @@
1
+ "use strict";
2
+
1
3
  const zlib = require('zlib');
2
4
  const lzma = require('lzma-native');
3
-
4
- exports.compress = async (data) => {
5
+ exports.compress = async data => {
5
6
  try {
6
7
  const brotliParams = {
7
8
  params: {
@@ -11,32 +12,25 @@ exports.compress = async (data) => {
11
12
  [zlib.constants.BROTLI_PARAM_LGWIN]: 24
12
13
  }
13
14
  };
14
-
15
15
  const brotliCompressed = await new Promise((resolve, reject) => {
16
16
  zlib.brotliCompress(Buffer.from(data, 'utf8'), brotliParams, (err, compressed) => {
17
- if (err) reject(err);
18
- else resolve(compressed);
17
+ if (err) reject(err);else resolve(compressed);
19
18
  });
20
19
  });
21
-
22
20
  const lzmaCompressed = await lzma.compress(brotliCompressed, 9);
23
21
  return lzmaCompressed;
24
22
  } catch (error) {
25
23
  throw new Error(`Compression error: ${error.message}`);
26
24
  }
27
25
  };
28
-
29
- exports.decompress = async (data) => {
26
+ exports.decompress = async data => {
30
27
  try {
31
28
  const lzmaDecompressed = await lzma.decompress(data);
32
-
33
29
  const brotliDecompressed = await new Promise((resolve, reject) => {
34
30
  zlib.brotliDecompress(lzmaDecompressed, (err, decompressed) => {
35
- if (err) reject(err);
36
- else resolve(decompressed);
31
+ if (err) reject(err);else resolve(decompressed);
37
32
  });
38
33
  });
39
-
40
34
  return brotliDecompressed;
41
35
  } catch (error) {
42
36
  throw new Error(`Decompression error: ${error.message}`);
@@ -1,7 +1,12 @@
1
- const crypto = require('crypto');
2
- const { IV_SIZE } = require('../constants');
3
- const { reverseBuffer } = require('./math');
1
+ "use strict";
4
2
 
3
+ const crypto = require('crypto');
4
+ const {
5
+ IV_SIZE
6
+ } = require('../constants');
7
+ const {
8
+ reverseBuffer
9
+ } = require('./math');
5
10
  exports.encrypt = (data, key) => {
6
11
  const iv1 = crypto.randomBytes(IV_SIZE);
7
12
  const cipher1 = crypto.createCipheriv('aes-256-gcm', key, iv1);
@@ -25,10 +30,16 @@ exports.encrypt = (data, key) => {
25
30
  let encrypted5 = cipher5.update(encrypted4);
26
31
  encrypted5 = Buffer.concat([encrypted5, cipher5.final()]);
27
32
  const permutedEncrypted = reverseBuffer(encrypted5);
28
-
29
- return { iv1, iv2, iv3, iv4, iv5, encrypted: permutedEncrypted, tag1 };
33
+ return {
34
+ iv1,
35
+ iv2,
36
+ iv3,
37
+ iv4,
38
+ iv5,
39
+ encrypted: permutedEncrypted,
40
+ tag1
41
+ };
30
42
  };
31
-
32
43
  exports.decrypt = (encrypted, key, iv1, iv2, iv3, iv4, iv5, tag1) => {
33
44
  const originalEncrypted = reverseBuffer(encrypted, true);
34
45
  const decipher5 = crypto.createDecipheriv('aes-256-ctr', key, iv5);
@@ -47,6 +58,5 @@ exports.decrypt = (encrypted, key, iv1, iv2, iv3, iv4, iv5, tag1) => {
47
58
  decipher1.setAuthTag(tag1);
48
59
  let decrypted1 = decipher1.update(decrypted2);
49
60
  decrypted1 = Buffer.concat([decrypted1, decipher1.final()]);
50
-
51
61
  return decrypted1;
52
62
  };
@@ -1,13 +1,16 @@
1
- const crypto = require('crypto');
2
- const { HMAC_KEY } = require('../constants');
3
- const { reverseHash } = require('./math');
1
+ "use strict";
4
2
 
5
- exports.hash = (data) => {
3
+ const crypto = require('crypto');
4
+ const {
5
+ HMAC_KEY
6
+ } = require('../constants');
7
+ const {
8
+ reverseHash
9
+ } = require('./math');
10
+ exports.hash = data => {
6
11
  const hmac = crypto.createHmac('sha512', HMAC_KEY);
7
12
  hmac.update(data);
8
13
  const digest = hmac.digest();
9
-
10
14
  return reverseHash(digest);
11
15
  };
12
-
13
16
  exports.verifyHash = (data, hash) => crypto.timingSafeEqual(exports.hash(data), hash);
@@ -1,15 +1,20 @@
1
- const crypto = require('crypto');
2
- const { PBKDF2_ITERATIONS, KEY_SIZE, PEPPER } = require('../constants');
3
- const { enhanceKey } = require('./math');
1
+ "use strict";
4
2
 
3
+ const crypto = require('crypto');
4
+ const {
5
+ PBKDF2_ITERATIONS,
6
+ KEY_SIZE,
7
+ PEPPER
8
+ } = require('../constants');
9
+ const {
10
+ enhanceKey
11
+ } = require('./math');
5
12
  exports.deriveKey = (password, salt) => {
6
13
  return new Promise((resolve, reject) => {
7
14
  const pepperedPassword = password + PEPPER;
8
15
  crypto.pbkdf2(pepperedPassword, salt, PBKDF2_ITERATIONS, KEY_SIZE, 'sha512', (err, key) => {
9
16
  if (err) reject(err);
10
-
11
17
  const enhancedKey = enhanceKey(key);
12
-
13
18
  resolve(enhancedKey);
14
19
  });
15
20
  });
@@ -1,14 +1,14 @@
1
+ "use strict";
2
+
1
3
  exports.reverseBuffer = (data, reverse = false) => {
2
4
  if (reverse) {
3
5
  return Buffer.from(data.toString('hex').split('').reverse().join(''), 'hex');
4
6
  }
5
7
  return Buffer.from(data.toString('hex').split('').reverse().join(''), 'hex');
6
8
  };
7
-
8
- exports.reverseHash = (hash) => {
9
+ exports.reverseHash = hash => {
9
10
  return Buffer.from(hash.toString('hex').split('').reverse().join(''), 'hex');
10
11
  };
11
-
12
- exports.enhanceKey = (key) => {
12
+ exports.enhanceKey = key => {
13
13
  return Buffer.from(key.toString('hex').split('').reverse().join(''), 'hex');
14
- };
14
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ SALT_SIZE: 32,
5
+ IV_SIZE: 16,
6
+ KEY_SIZE: 32,
7
+ TAG_SIZE: 16,
8
+ PBKDF2_ITERATIONS: 310000,
9
+ HASH_SEED: 0xCAFEBABE,
10
+ PEPPER: 'veryLongAndComplexPepperValue123!@#$%^&*()_+[]{}|;:,.<>?',
11
+ HMAC_KEY: 'veryLongAndComplexHMACKeyValue456!@#$%^&*()_+[]{}|;:,.<>?'
12
+ };
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ const crypto = require('crypto');
4
+ const {
5
+ compress,
6
+ decompress
7
+ } = require('./utils/compression');
8
+ const {
9
+ deriveKey
10
+ } = require('./utils/keyDerivation');
11
+ const {
12
+ encrypt,
13
+ decrypt
14
+ } = require('./utils/encryption');
15
+ const {
16
+ hash,
17
+ verifyHash
18
+ } = require('./utils/hashing');
19
+ const {
20
+ SALT_SIZE,
21
+ IV_SIZE,
22
+ TAG_SIZE
23
+ } = require('./constants');
24
+ class K9crypt {
25
+ constructor(secretKey) {
26
+ if (!secretKey) {
27
+ this.secretKey = crypto.randomBytes(50);
28
+ this._autoGenerated = true;
29
+ } else {
30
+ this._autoGenerated = false;
31
+ this.secretKey = secretKey;
32
+ }
33
+ }
34
+ getGenerated() {
35
+ return this._autoGenerated ? this.secretKey : null;
36
+ }
37
+ async encrypt(plaintext) {
38
+ try {
39
+ const compressed = await compress(plaintext);
40
+ const salt = crypto.randomBytes(SALT_SIZE);
41
+ const key = await deriveKey(this.secretKey, salt);
42
+ const {
43
+ iv1,
44
+ iv2,
45
+ iv3,
46
+ iv4,
47
+ iv5,
48
+ encrypted,
49
+ tag1
50
+ } = encrypt(compressed, key);
51
+ const dataToHash = Buffer.concat([salt, iv1, iv2, iv3, iv4, iv5, encrypted, tag1]);
52
+ const dataHash = hash(dataToHash);
53
+ const result = Buffer.concat([salt, iv1, iv2, iv3, iv4, iv5, encrypted, tag1, dataHash]);
54
+ return result.toString('base64');
55
+ } catch (error) {
56
+ console.log('Encryption failed');
57
+ }
58
+ }
59
+ async decrypt(ciphertext) {
60
+ try {
61
+ const data = Buffer.from(ciphertext, 'base64');
62
+ const salt = data.slice(0, SALT_SIZE);
63
+ const iv1 = data.slice(SALT_SIZE, SALT_SIZE + IV_SIZE);
64
+ const iv2 = data.slice(SALT_SIZE + IV_SIZE, SALT_SIZE + 2 * IV_SIZE);
65
+ const iv3 = data.slice(SALT_SIZE + 2 * IV_SIZE, SALT_SIZE + 3 * IV_SIZE);
66
+ const iv4 = data.slice(SALT_SIZE + 3 * IV_SIZE, SALT_SIZE + 4 * IV_SIZE);
67
+ const iv5 = data.slice(SALT_SIZE + 4 * IV_SIZE, SALT_SIZE + 5 * IV_SIZE);
68
+ const encrypted = data.slice(SALT_SIZE + 5 * IV_SIZE, -TAG_SIZE - 64);
69
+ const tag1 = data.slice(-TAG_SIZE - 64, -64);
70
+ const dataHash = data.slice(-64);
71
+ const dataToVerify = data.slice(0, -64);
72
+ if (!verifyHash(dataToVerify, dataHash)) {
73
+ console.log('Data integrity check failed');
74
+ }
75
+ const key = await deriveKey(this.secretKey, salt);
76
+ const decrypted = decrypt(encrypted, key, iv1, iv2, iv3, iv4, iv5, tag1);
77
+ const decompressed = await decompress(decrypted);
78
+ return decompressed.toString('utf8');
79
+ } catch (error) {
80
+ console.log('Decryption failed');
81
+ }
82
+ }
83
+ }
84
+ module.exports = K9crypt;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ const zlib = require('zlib');
4
+ const lzma = require('lzma-native');
5
+ exports.compress = async data => {
6
+ try {
7
+ const brotliParams = {
8
+ params: {
9
+ [zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
10
+ [zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
11
+ [zlib.constants.BROTLI_PARAM_SIZE_HINT]: Buffer.byteLength(data, 'utf8'),
12
+ [zlib.constants.BROTLI_PARAM_LGWIN]: 24
13
+ }
14
+ };
15
+ const brotliCompressed = await new Promise((resolve, reject) => {
16
+ zlib.brotliCompress(Buffer.from(data, 'utf8'), brotliParams, (err, compressed) => {
17
+ if (err) reject(err);else resolve(compressed);
18
+ });
19
+ });
20
+ const lzmaCompressed = await lzma.compress(brotliCompressed, 9);
21
+ return lzmaCompressed;
22
+ } catch (error) {
23
+ throw new Error(`Compression error: ${error.message}`);
24
+ }
25
+ };
26
+ exports.decompress = async data => {
27
+ try {
28
+ const lzmaDecompressed = await lzma.decompress(data);
29
+ const brotliDecompressed = await new Promise((resolve, reject) => {
30
+ zlib.brotliDecompress(lzmaDecompressed, (err, decompressed) => {
31
+ if (err) reject(err);else resolve(decompressed);
32
+ });
33
+ });
34
+ return brotliDecompressed;
35
+ } catch (error) {
36
+ throw new Error(`Decompression error: ${error.message}`);
37
+ }
38
+ };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ const crypto = require('crypto');
4
+ const {
5
+ IV_SIZE
6
+ } = require('../constants');
7
+ const {
8
+ reverseBuffer
9
+ } = require('./math');
10
+ exports.encrypt = (data, key) => {
11
+ const iv1 = crypto.randomBytes(IV_SIZE);
12
+ const cipher1 = crypto.createCipheriv('aes-256-gcm', key, iv1);
13
+ let encrypted1 = cipher1.update(data);
14
+ encrypted1 = Buffer.concat([encrypted1, cipher1.final()]);
15
+ const tag1 = cipher1.getAuthTag();
16
+ const iv2 = crypto.randomBytes(IV_SIZE);
17
+ const cipher2 = crypto.createCipheriv('aes-256-cbc', key, iv2);
18
+ let encrypted2 = cipher2.update(encrypted1);
19
+ encrypted2 = Buffer.concat([encrypted2, cipher2.final()]);
20
+ const iv3 = crypto.randomBytes(IV_SIZE);
21
+ const cipher3 = crypto.createCipheriv('aes-256-cfb', key, iv3);
22
+ let encrypted3 = cipher3.update(encrypted2);
23
+ encrypted3 = Buffer.concat([encrypted3, cipher3.final()]);
24
+ const iv4 = crypto.randomBytes(IV_SIZE);
25
+ const cipher4 = crypto.createCipheriv('aes-256-ofb', key, iv4);
26
+ let encrypted4 = cipher4.update(encrypted3);
27
+ encrypted4 = Buffer.concat([encrypted4, cipher4.final()]);
28
+ const iv5 = crypto.randomBytes(IV_SIZE);
29
+ const cipher5 = crypto.createCipheriv('aes-256-ctr', key, iv5);
30
+ let encrypted5 = cipher5.update(encrypted4);
31
+ encrypted5 = Buffer.concat([encrypted5, cipher5.final()]);
32
+ const permutedEncrypted = reverseBuffer(encrypted5);
33
+ return {
34
+ iv1,
35
+ iv2,
36
+ iv3,
37
+ iv4,
38
+ iv5,
39
+ encrypted: permutedEncrypted,
40
+ tag1
41
+ };
42
+ };
43
+ exports.decrypt = (encrypted, key, iv1, iv2, iv3, iv4, iv5, tag1) => {
44
+ const originalEncrypted = reverseBuffer(encrypted, true);
45
+ const decipher5 = crypto.createDecipheriv('aes-256-ctr', key, iv5);
46
+ let decrypted5 = decipher5.update(originalEncrypted);
47
+ decrypted5 = Buffer.concat([decrypted5, decipher5.final()]);
48
+ const decipher4 = crypto.createDecipheriv('aes-256-ofb', key, iv4);
49
+ let decrypted4 = decipher4.update(decrypted5);
50
+ decrypted4 = Buffer.concat([decrypted4, decipher4.final()]);
51
+ const decipher3 = crypto.createDecipheriv('aes-256-cfb', key, iv3);
52
+ let decrypted3 = decipher3.update(decrypted4);
53
+ decrypted3 = Buffer.concat([decrypted3, decipher3.final()]);
54
+ const decipher2 = crypto.createDecipheriv('aes-256-cbc', key, iv2);
55
+ let decrypted2 = decipher2.update(decrypted3);
56
+ decrypted2 = Buffer.concat([decrypted2, decipher2.final()]);
57
+ const decipher1 = crypto.createDecipheriv('aes-256-gcm', key, iv1);
58
+ decipher1.setAuthTag(tag1);
59
+ let decrypted1 = decipher1.update(decrypted2);
60
+ decrypted1 = Buffer.concat([decrypted1, decipher1.final()]);
61
+ return decrypted1;
62
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ const crypto = require('crypto');
4
+ const {
5
+ HMAC_KEY
6
+ } = require('../constants');
7
+ const {
8
+ reverseHash
9
+ } = require('./math');
10
+ exports.hash = data => {
11
+ const hmac = crypto.createHmac('sha512', HMAC_KEY);
12
+ hmac.update(data);
13
+ const digest = hmac.digest();
14
+ return reverseHash(digest);
15
+ };
16
+ exports.verifyHash = (data, hash) => crypto.timingSafeEqual(exports.hash(data), hash);
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ const crypto = require('crypto');
4
+ const {
5
+ PBKDF2_ITERATIONS,
6
+ KEY_SIZE,
7
+ PEPPER
8
+ } = require('../constants');
9
+ const {
10
+ enhanceKey
11
+ } = require('./math');
12
+ exports.deriveKey = (password, salt) => {
13
+ return new Promise((resolve, reject) => {
14
+ const pepperedPassword = password + PEPPER;
15
+ crypto.pbkdf2(pepperedPassword, salt, PBKDF2_ITERATIONS, KEY_SIZE, 'sha512', (err, key) => {
16
+ if (err) reject(err);
17
+ const enhancedKey = enhanceKey(key);
18
+ resolve(enhancedKey);
19
+ });
20
+ });
21
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ exports.reverseBuffer = (data, reverse = false) => {
4
+ if (reverse) {
5
+ return Buffer.from(data.toString('hex').split('').reverse().join(''), 'hex');
6
+ }
7
+ return Buffer.from(data.toString('hex').split('').reverse().join(''), 'hex');
8
+ };
9
+ exports.reverseHash = hash => {
10
+ return Buffer.from(hash.toString('hex').split('').reverse().join(''), 'hex');
11
+ };
12
+ exports.enhanceKey = key => {
13
+ return Buffer.from(key.toString('hex').split('').reverse().join(''), 'hex');
14
+ };
package/package.json CHANGED
@@ -1,10 +1,24 @@
1
1
  {
2
2
  "name": "k9crypt",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "A special encryption algorithm created for K9Crypt.",
5
- "main": "index.js",
5
+ "type": "module",
6
+ "main": "./dist/cjs/index.js",
7
+ "module": "./dist/esm/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/esm/index.js",
11
+ "require": "./dist/cjs/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
6
17
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
18
+ "test": "echo \"Error: no test specified\" && exit 1",
19
+ "build:esm": "babel src --out-dir dist/esm --copy-files",
20
+ "build:cjs": "babel src --out-dir dist/cjs --copy-files --config-file ./babel.config.cjs",
21
+ "build": "bun run build:esm && bun run build:cjs"
8
22
  },
9
23
  "keywords": [
10
24
  "secure",
@@ -32,5 +46,10 @@
32
46
  "bugs": {
33
47
  "url": "https://github.com/K9Crypt/module/issues"
34
48
  },
35
- "homepage": "https://k9crypt.xyz"
49
+ "homepage": "https://k9crypt.xyz",
50
+ "devDependencies": {
51
+ "@babel/cli": "^7.28.0",
52
+ "@babel/core": "^7.28.0",
53
+ "@babel/preset-env": "^7.28.0"
54
+ }
36
55
  }
package/index.js DELETED
@@ -1,3 +0,0 @@
1
- const k9crypt = require('./src/index');
2
-
3
- module.exports = k9crypt;