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 +24 -16
- package/package.json +1 -1
- package/src/index.js +12 -2
- package/src/utils/encryption.js +1 -1
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
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
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
|
-
|
|
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;
|
package/src/utils/encryption.js
CHANGED