-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
5 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,18 +41,18 @@ If you don't like NPM, a standalone | |
|
||
```js | ||
// import * from '@noble/ciphers'; // Error: use sub-imports, to ensure small app size | ||
|
||
// Simple chacha: xchacha20poly1305 with prepended-to-ciphertext random nonce: | ||
// nonce || ciphertext || mac | ||
import { encrypt, decrypt, utf8ToBytes, randomKey } from '@noble/ciphers/simple'; | ||
// import { encrypt, decrypt } from 'npm:@noble/[email protected]/simple'; // Deno | ||
|
||
// Simple chacha API: xchacha20poly1305 with random nonce. | ||
// Nonce is prepended to ciphertext: (nonce || ciphertext || mac) | ||
const key = randomKey(); | ||
const plaintext = utf8ToBytes('hello'); // Library works over Uint8Array-s | ||
const ciphertext = encrypt(key, plaintext); | ||
const plaintext_ = decrypt(key, ciphertext); // == plaintext | ||
|
||
// Simple AES API: aes_256_gcm with random nonce. | ||
// Nonce is auto-prepended to ciphertext: (nonce || ciphertext || mac) | ||
// Simple AES: AES-256-GCM with prepended-to-ciphertext random nonce: | ||
// nonce || ciphertext || mac | ||
import { aes_encrypt, aes_decrypt } from '@noble/ciphers/simple'; | ||
const a_key = randomKey(); | ||
const a_ciphertext = await aes_encrypt(a_key, plaintext); | ||
|