cipher-kit 2.0.0 → 2.1.1
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 +26 -28
- package/dist/{chunk-N2EW2FDZ.cjs → chunk-56PVVFVM.cjs} +187 -152
- package/dist/chunk-56PVVFVM.cjs.map +1 -0
- package/dist/{chunk-FKSYSPJR.js → chunk-6C4NIWQ4.js} +24 -22
- package/dist/chunk-6C4NIWQ4.js.map +1 -0
- package/dist/{chunk-4MFF6V3R.js → chunk-FSEA3UXJ.js} +80 -45
- package/dist/chunk-FSEA3UXJ.js.map +1 -0
- package/dist/{chunk-CVCDAHDW.cjs → chunk-LTVOIZP5.cjs} +193 -158
- package/dist/chunk-LTVOIZP5.cjs.map +1 -0
- package/dist/{chunk-ACFPMIXO.js → chunk-PWTFVMW6.js} +79 -44
- package/dist/chunk-PWTFVMW6.js.map +1 -0
- package/dist/{chunk-3UX5MZ2P.cjs → chunk-X4CS7UXE.cjs} +25 -22
- package/dist/chunk-X4CS7UXE.cjs.map +1 -0
- package/dist/{export-55tHE0Bw.d.cts → export-C4DbO5zM.d.ts} +200 -26
- package/dist/{export-llM6c7Do.d.ts → export-CpZ7s25O.d.cts} +200 -26
- package/dist/{export-CQNsJFh_.d.cts → export-DO9n7Np-.d.cts} +200 -26
- package/dist/{export-BMvZq46v.d.ts → export-DUgIcobC.d.ts} +200 -26
- package/dist/index.cjs +12 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/node.cjs +33 -33
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +2 -2
- package/dist/{validate-EHuJC5QQ.d.cts → validate-cJEdGlj1.d.cts} +54 -67
- package/dist/{validate-EHuJC5QQ.d.ts → validate-cJEdGlj1.d.ts} +54 -67
- package/dist/web-api.cjs +33 -33
- package/dist/web-api.d.cts +2 -2
- package/dist/web-api.d.ts +2 -2
- package/dist/web-api.js +2 -2
- package/package.json +6 -7
- package/dist/chunk-3UX5MZ2P.cjs.map +0 -1
- package/dist/chunk-4MFF6V3R.js.map +0 -1
- package/dist/chunk-ACFPMIXO.js.map +0 -1
- package/dist/chunk-CVCDAHDW.cjs.map +0 -1
- package/dist/chunk-FKSYSPJR.js.map +0 -1
- package/dist/chunk-N2EW2FDZ.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -41,24 +41,24 @@ bun add cipher-kit@latest
|
|
|
41
41
|
## Quick Start 🚀
|
|
42
42
|
|
|
43
43
|
```typescript
|
|
44
|
-
// Node.js
|
|
44
|
+
// Node.js
|
|
45
45
|
import { createSecretKey, encrypt, decrypt } from "cipher-kit/node";
|
|
46
46
|
|
|
47
|
-
const
|
|
48
|
-
const encrypted = encrypt("Hello World!",
|
|
49
|
-
const decrypted = decrypt(encrypted,
|
|
47
|
+
const secretKey = createSecretKey("my-passphrase");
|
|
48
|
+
const encrypted = encrypt("Hello World!", secretKey);
|
|
49
|
+
const decrypted = decrypt(encrypted, secretKey);
|
|
50
50
|
console.log(decrypted); // "Hello World!"
|
|
51
51
|
|
|
52
|
-
// Web
|
|
52
|
+
// Web - including Deno, Bun, Cloudflare Workers
|
|
53
53
|
import { createSecretKey, encrypt, decrypt } from "cipher-kit/web-api";
|
|
54
54
|
|
|
55
|
-
const
|
|
56
|
-
const encrypted = await encrypt("Hello World!",
|
|
57
|
-
const decrypted = await decrypt(encrypted,
|
|
55
|
+
const secretKey = await createSecretKey("my-passphrase");
|
|
56
|
+
const encrypted = await encrypt("Hello World!", secretKey);
|
|
57
|
+
const decrypted = await decrypt(encrypted, secretKey);
|
|
58
58
|
console.log(decrypted); // "Hello World!"
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
##
|
|
61
|
+
## API Reference 📚
|
|
62
62
|
|
|
63
63
|
Table of Contents:
|
|
64
64
|
|
|
@@ -129,6 +129,7 @@ Encryption is the process of converting readable plaintext into unreadable ciphe
|
|
|
129
129
|
#### _Secret Key Creation_ 🔑
|
|
130
130
|
|
|
131
131
|
Before encrypting or decrypting data, you need to create a secret key.
|
|
132
|
+
The key must be at least 8 characters long.
|
|
132
133
|
|
|
133
134
|
Each key is tied to a specific platform (Web or Node.js) and cannot be used interchangeably.
|
|
134
135
|
|
|
@@ -188,7 +189,7 @@ The function accepts an optional `options` parameter to customize the output enc
|
|
|
188
189
|
```typescript
|
|
189
190
|
interface EncryptOptions {
|
|
190
191
|
// Output ciphertext encoding(default: "base64url")
|
|
191
|
-
|
|
192
|
+
outputEncoding?: "base64url" | "base64" | "hex";
|
|
192
193
|
}
|
|
193
194
|
```
|
|
194
195
|
|
|
@@ -217,7 +218,7 @@ Make sure to use the same encoding that was used during encryption.
|
|
|
217
218
|
```typescript
|
|
218
219
|
interface DecryptOptions {
|
|
219
220
|
// Input ciphertext encoding (default: "base64url")
|
|
220
|
-
|
|
221
|
+
inputEncoding?: "base64url" | "base64" | "hex";
|
|
221
222
|
}
|
|
222
223
|
```
|
|
223
224
|
|
|
@@ -275,7 +276,7 @@ interface HashOptions {
|
|
|
275
276
|
digest?: "sha256" | "sha384" | "sha512";
|
|
276
277
|
|
|
277
278
|
// Output encoding (default: "base64url").
|
|
278
|
-
|
|
279
|
+
outputEncoding?: "base64url" | "base64" | "hex";
|
|
279
280
|
}
|
|
280
281
|
```
|
|
281
282
|
|
|
@@ -309,19 +310,19 @@ To verify a password, the same hashing process is applied to the input password,
|
|
|
309
310
|
// Node.js example
|
|
310
311
|
import { hashPassword, verifyPassword } from "cipher-kit/node";
|
|
311
312
|
|
|
312
|
-
const {
|
|
313
|
-
console.log(`Hashed Password: ${
|
|
313
|
+
const { result, salt } = hashPassword("some-secure-password");
|
|
314
|
+
console.log(`Hashed Password: ${result}`);
|
|
314
315
|
|
|
315
|
-
const isMatch = verifyPassword("some-secure-password",
|
|
316
|
+
const isMatch = verifyPassword("some-secure-password", result, salt);
|
|
316
317
|
console.log(`Password match: ${isMatch}`);
|
|
317
318
|
|
|
318
319
|
// Web example
|
|
319
320
|
import { hashPassword, verifyPassword } from "cipher-kit/web-api";
|
|
320
321
|
|
|
321
|
-
const {
|
|
322
|
-
console.log(`Hashed Password: ${
|
|
322
|
+
const { result, salt } = await hashPassword("some-secure-password");
|
|
323
|
+
console.log(`Hashed Password: ${result}`);
|
|
323
324
|
|
|
324
|
-
const isMatch = await verifyPassword("some-secure-password",
|
|
325
|
+
const isMatch = await verifyPassword("some-secure-password", result, salt);
|
|
325
326
|
console.log(`Password match: ${isMatch}`);
|
|
326
327
|
```
|
|
327
328
|
|
|
@@ -333,7 +334,7 @@ interface HashPasswordOptions {
|
|
|
333
334
|
digest?: "sha256" | "sha384" | "sha512";
|
|
334
335
|
|
|
335
336
|
// Encoding format for the output hash (default: "base64url").
|
|
336
|
-
|
|
337
|
+
outputEncoding?: "base64url" | "base64" | "hex";
|
|
337
338
|
|
|
338
339
|
// Length of the salt in bytes (default: 16 bytes, min: 8 bytes).
|
|
339
340
|
saltLength?: number;
|
|
@@ -350,7 +351,7 @@ interface VerifyPasswordOptions {
|
|
|
350
351
|
digest?: "sha256" | "sha384" | "sha512";
|
|
351
352
|
|
|
352
353
|
// Encoding format used during the original hashing (default: `'base64url'`).
|
|
353
|
-
|
|
354
|
+
inputEncoding?: "base64url" | "base64" | "hex";
|
|
354
355
|
|
|
355
356
|
// Number of iterations used during the original hashing (default: `320000`).
|
|
356
357
|
iterations?: number;
|
|
@@ -404,10 +405,10 @@ Regular expressions (regex) are sequences of characters that form search pattern
|
|
|
404
405
|
Before decrypting, you can validate the format (decryption functions already validate internally).
|
|
405
406
|
|
|
406
407
|
```typescript
|
|
407
|
-
import { ENCRYPTED_REGEX,
|
|
408
|
+
import { ENCRYPTED_REGEX, matchEncryptedPattern } from "cipher-kit"; // works in both "cipher-kit/web-api" and "cipher-kit/node"
|
|
408
409
|
|
|
409
410
|
function isEncryptedFormat(message: string): boolean {
|
|
410
|
-
return
|
|
411
|
+
return matchEncryptedPattern(message, "general"); // or "node" or "web"
|
|
411
412
|
}
|
|
412
413
|
|
|
413
414
|
// or
|
|
@@ -419,18 +420,15 @@ function isEncryptedFormat(message: string): boolean {
|
|
|
419
420
|
|
|
420
421
|
## Contributions 🤝
|
|
421
422
|
|
|
422
|
-
Want to contribute or suggest a feature?
|
|
423
|
+
Want to contribute or suggest a feature or improvement?
|
|
423
424
|
|
|
424
425
|
- Open an issue or feature request
|
|
425
426
|
- Submit a PR to improve the packages or add new ones
|
|
426
427
|
- Star ⭐ the repo if you like what you see
|
|
427
428
|
|
|
428
|
-
## License 📜
|
|
429
|
-
|
|
430
|
-
This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).
|
|
431
|
-
|
|
432
429
|
<div align="center">
|
|
433
430
|
<br/>
|
|
434
431
|
<div style="font-size: 14px; font-weight:bold;"> ⚒️ Crafted carefully by <a href="https://github.com/WolfieLeader" target="_blank" rel="nofollow">WolfieLeader</a></div>
|
|
435
|
-
<
|
|
432
|
+
<p style="font-size: 12px; font-style: italic;">This project is licensed under the <a href="https://opensource.org/licenses/MIT" target="_blank" rel="nofollow">MIT License</a>.</p>
|
|
433
|
+
<div style="font-size: 12px; font-style: italic; font-weight: 600;">Thank you!</div>
|
|
436
434
|
</div>
|