Skip to content

Commit 83b2b50

Browse files
committed
docs: some fixes
1 parent 0986ca1 commit 83b2b50

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A simple, secure, and fast symmetric encryption library that makes use of [AES-G
77

88
## Why AES-GCM?
99

10-
AES-GCM is extremely fast on modern CPUs, which have dedicated hardware acceleration ([AES-NI](https://en.wikipedia.org/wiki/AES_instruction_set)), in addition to being highly secure and even quantum-resistant (AES-128-GCM).
10+
AES-GCM is extremely fast on modern CPUs, which have dedicated hardware acceleration ([AES-NI](https://en.wikipedia.org/wiki/AES_instruction_set)), in addition to being highly secure and even quantum-resistant (AES-256-GCM).
1111

1212
## Installation
1313

@@ -21,12 +21,12 @@ bun add singlecrypt
2121

2222
#### `createSymmetricCryptoKey`
2323

24-
Creates a symmetric `CryptoKey` object to be used in the following methods. It takes two parameters:
24+
Creates a symmetric `CryptoKey` object to be used in the following methods. This method also converts your value key to a SHA-256 hash. It takes two parameters:
2525

2626
1. A string key to be hashed. A 32-byte random string is recommended.
2727
2. A `TextEncoder` instance, if you want to reuse it (optional).
2828

29-
Returns a `Promise<CryptoKey>`.
29+
Returns a `Promise<CryptoKey>` containing a SHA-256 hash used to encrypt and decrypt strings.
3030

3131
A `TypeError` may be thrown if there are problems with the string key.
3232

@@ -72,15 +72,23 @@ import {
7272
} from "singlecrypt";
7373

7474

75-
const userCryptoKey = await createSymmetricCryptoKey(process.env.KEY_USER);
75+
const userCryptoKey = await createSymmetricCryptoKey(
76+
process.env.KEY_USER
77+
);
7678

7779

7880
export async function encryptUserId(value: string) {
79-
return await encryptSymmetrically(value, userCryptoKey);
81+
return await encryptSymmetrically(
82+
value,
83+
userCryptoKey
84+
);
8085
}
8186

8287
export async function decryptUserId(value: string) {
83-
return await decryptSymmetrically(value, userCryptoKey);
88+
return await decryptSymmetrically(
89+
value,
90+
userCryptoKey
91+
);
8492
}
8593
```
8694

@@ -104,11 +112,19 @@ const userCryptoKey = await createSymmetricCryptoKey(
104112

105113

106114
export async function encryptUserId(value: string) {
107-
return await encryptSymmetrically(value, userCryptoKey, textEncoder);
115+
return await encryptSymmetrically(
116+
value,
117+
userCryptoKey,
118+
textEncoder
119+
);
108120
}
109121

110122
export async function decryptUserId(value: string) {
111-
return await decryptSymmetrically(value, userCryptoKey, textDecoder);
123+
return await decryptSymmetrically(
124+
value,
125+
userCryptoKey,
126+
textDecoder
127+
);
112128
}
113129
```
114130

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ const keyUsages = ["encrypt", "decrypt"]
77

88
/**
99
* Before encrypting and decrypting values, a symmetric `CryptoKey` must be created.
10+
* This method also converts your value key to a SHA-256 hash.
1011
*
1112
* @param {string} value - String key to be hashed. A 32-byte random string is recommended.
1213
* @param {TextEncoder} [textEncoder] - If you have an instance of a `TextEncoder`, you can reuse it.
13-
* @returns {Promise<CryptoKey>} A `CryptoKey` used to encrypt and decrypt strings.
14+
* @returns {Promise<CryptoKey>} A `CryptoKey` containing a SHA-256 hash used to encrypt and decrypt strings.
1415
* @throws {TypeError} Thrown if `value` is invalid.
1516
*/
1617
export async function createSymmetricCryptoKey(

0 commit comments

Comments
 (0)