k9crypt 1.1.2 → 1.1.3

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,13 +5,18 @@
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.3**
10
+
11
+ - Users no longer need to manually define a key. The system now automatically generates a secure key. However, users who prefer can still provide their own key if they wish.
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
@@ -20,23 +25,26 @@ npm install k9crypt
20
25
  const k9crypt = require('k9crypt');
21
26
 
22
27
  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
- }
28
+ const secretKey = 'VeryLongSecretKey!@#1234567890';
29
+ const encryptor = new k9crypt(secretKey);
30
+ // Or you can use it without providing a secretKey value. A key will be generated by the system.
31
+ // const encryptor = new k9crypt();
32
+ const plaintext = 'Hello, World!';
33
+
34
+ try {
35
+ const encrypted = await encryptor.encrypt(plaintext);
36
+ console.log('Encrypted data:', encrypted);
37
+
38
+ const decrypted = await encryptor.decrypt(encrypted);
39
+ console.log('Decrypted data:', decrypted);
40
+ } catch (error) {
41
+ console.error('Encryption error:', error);
42
+ }
36
43
  }
37
44
 
38
45
  test();
39
46
  ```
40
47
 
41
48
  ## License
49
+
42
50
  This project is licensed under the MIT license.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k9crypt",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "A special encryption algorithm created for K9Crypt.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -7,7 +7,17 @@ const { SALT_SIZE, IV_SIZE, TAG_SIZE } = require('./constants');
7
7
 
8
8
  class K9crypt {
9
9
  constructor(secretKey) {
10
- this.secretKey = secretKey;
10
+ if (!secretKey) {
11
+ this.secretKey = crypto.randomBytes(50);
12
+ this._autoGenerated = true;
13
+ } else {
14
+ this._autoGenerated = false;
15
+ this.secretKey = secretKey;
16
+ }
17
+ }
18
+
19
+ getGenerated() {
20
+ return this._autoGenerated ? this.secretKey : null;
11
21
  }
12
22
 
13
23
  async encrypt(plaintext) {
@@ -53,4 +63,4 @@ class K9crypt {
53
63
  }
54
64
  }
55
65
 
56
- module.exports = K9crypt;
66
+ module.exports = K9crypt;
@@ -49,4 +49,4 @@ exports.decrypt = (encrypted, key, iv1, iv2, iv3, iv4, iv5, tag1) => {
49
49
  decrypted1 = Buffer.concat([decrypted1, decipher1.final()]);
50
50
 
51
51
  return decrypted1;
52
- };
52
+ };