Skip to content

Commit 0bb2c34

Browse files
committed
cipher kit version 2 published!
1 parent 42db50d commit 0bb2c34

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

packages/cipher-kit/README.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<p align="center">
77
Secure, Modern, and Cross-Platform <br/>
8-
Cryptography Helpers for Web, Node.js <br/>
8+
Cryptography Helpers for Web, Node.js, <br/>
99
Deno, Bun, and Cloudflare Workers
1010
</p>
1111

@@ -41,15 +41,21 @@ bun add cipher-kit@latest
4141
## Quick Start 🚀
4242

4343
```typescript
44-
import { createSecretKey, encrypt, decrypt } from "cipher-kit/node"; // or "cipher-kit/web-api"
44+
// Node.js Quick Start
45+
import { createSecretKey, encrypt, decrypt } from "cipher-kit/node";
4546

46-
const secretKey = createSecretKey("my-passphrase");
47+
const nodeSecretKey = createSecretKey("my-passphrase");
48+
const encrypted = encrypt("Hello World!", nodeSecretKey);
49+
const decrypted = decrypt(encrypted, nodeSecretKey);
50+
console.log(decrypted); // "Hello World!"
4751

48-
const encrypted = encrypt("Hello, World!", secretKey);
49-
console.log(`Encrypted: ${encrypted}`); // Encrypted: <ciphertext>
52+
// Web Quick Start
53+
import { createSecretKey, encrypt, decrypt } from "cipher-kit/web-api";
5054

51-
const decrypted = decrypt(encrypted, secretKey);
52-
console.log(`Decrypted: ${decrypted}`); // Decrypted: Hello, World!
55+
const webSecretKey = await createSecretKey("my-passphrase");
56+
const encrypted = await encrypt("Hello World!", webSecretKey);
57+
const decrypted = await decrypt(encrypted, webSecretKey);
58+
console.log(decrypted); // "Hello World!"
5359
```
5460

5561
## Usage 🪛
@@ -245,6 +251,8 @@ The `encryptObj` and `decryptObj` functions accept the same `options` parameters
245251

246252
Hashing is a one-way process that uses an algorithm to transform data of any size into a fixed-length string of characters, called a hash value or digest. It serves as a digital fingerprint for the data, enabling quick data retrieval in hash tables, password storage, and file integrity checks. Key features include its irreversibility (you can't get the original data back from the hash).
247253

254+
Not suitable for storing passwords - use `hashPassword` instead.
255+
248256
```typescript
249257
// Node.js example
250258
import { hash } from "cipher-kit/node";
@@ -295,7 +303,7 @@ Password hashing is a one-way process that transforms a plaintext password into
295303

296304
Password hashing is different from general-purpose hashing because it often involves additional techniques like salting and key stretching to enhance security against brute-force attacks, and it's usually slower to compute to make rainbow table attacks less feasible.
297305

298-
To verify a password, the same hashing process is applied to the input password, and the resulting hash is compared to the stored hash, in a time-safe manner to prevent timing attacks.
306+
To verify a password, the same hashing process is applied to the input password, and the resulting hash is compared to the stored hash, in a constant-time comparison to prevent timing attacks.
299307

300308
```typescript
301309
// Node.js example
@@ -423,6 +431,6 @@ This project is licensed under the [MIT License](https://opensource.org/licenses
423431

424432
<div align="center">
425433
<br/>
426-
<p style="font-size: 14px; font-weight:bold;">Made by <a href="https://github.com/WolfieLeader" target="_blank" rel="nofollow">WolfieLeader</a></p>
427-
<p style="font-size: 12px; font-style: italic;">Thank you!</p>
434+
<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+
<div style="font-size: 12px; font-style: italic;">Thank you!</div>
428436
</div>

packages/cipher-kit/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cipher-kit",
3-
"version": "2.0.0-beta.5",
4-
"description": "🔐 Secure, Lightweight, and Cross-Platform Encryption, Decryption, and Hashing for Web, Node.js, Deno, Bun, and Cloudflare Workers",
3+
"version": "2.0.0",
4+
"description": "🔐 Secure, Modern, and Cross-Platform Cryptography Helpers for Web, Node.js, Deno, Bun, and Cloudflare Workers",
55
"homepage": "https://github.com/WolfieLeader/npm/tree/main/packages/cipher-kit#readme",
66
"repository": {
77
"type": "git",
@@ -87,6 +87,7 @@
8787
"deno",
8888
"bun",
8989
"cloudflare",
90-
"workers"
90+
"workers",
91+
"password"
9192
]
9293
}

packages/cipher-kit/src/__tests__/encrypt.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,43 @@ describe("Encryption", () => {
163163
expect(nodeKit.hash(data, { digest: "sha384" })).toBe(await webKit.hash(data, { digest: "sha384" }));
164164
expect(nodeKit.hash(data, { digest: "sha512" })).toBe(await webKit.hash(data, { digest: "sha512" }));
165165
});
166+
167+
test("Password Hash Test", async () => {
168+
const password = "SuperSecretPassword!";
169+
170+
const nodeHash = nodeKit.tryHashPassword(password);
171+
expect(nodeHash.success).toBe(true);
172+
expect(nodeHash.hash).toBeDefined();
173+
expect(nodeHash.salt).toBeDefined();
174+
175+
const webHash = await webKit.tryHashPassword(password);
176+
expect(webHash.success).toBe(true);
177+
expect(webHash.hash).toBeDefined();
178+
expect(webHash.salt).toBeDefined();
179+
180+
expect(nodeHash.hash).not.toBe(webHash.hash);
181+
expect(nodeHash.salt).not.toBe(webHash.salt);
182+
183+
const nodeVerify = nodeKit.verifyPassword(password, nodeHash.hash as string, nodeHash.salt as string);
184+
expect(nodeVerify).toBe(true);
185+
186+
const webVerify = await webKit.verifyPassword(password, webHash.hash as string, webHash.salt as string);
187+
expect(webVerify).toBe(true);
188+
189+
const nodeVerifyWrong = nodeKit.verifyPassword(
190+
"SuperSecredPassword",
191+
nodeHash.hash as string,
192+
nodeHash.salt as string,
193+
);
194+
expect(nodeVerifyWrong).toBe(false);
195+
196+
const webVerifyWrong = await webKit.verifyPassword(
197+
"SuperSecredPassword",
198+
webHash.hash as string,
199+
webHash.salt as string,
200+
);
201+
expect(webVerifyWrong).toBe(false);
202+
});
166203
});
167204

168205
const largeObj = {

0 commit comments

Comments
 (0)