Skip to content

Commit

Permalink
chore: improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
frytg committed Dec 17, 2024
1 parent f99fee1 commit e9519f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions crypto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

This package provides functions to compute SHA-256 and SHA-512 hashes using [native Node crypto](https://nodejs.org/api/crypto.html).

- [full docs on JSR](https://jsr.io/@frytg/crypto/doc)
- [Hash (SHA-256 or SHA-512)](https://jsr.io/@frytg/crypto/doc/hash)
- [HMAC (SHA-256 or SHA-512)](https://jsr.io/@frytg/crypto/doc/hmac)
- [full docs on _jsr.io_](https://jsr.io/@frytg/crypto/doc)
- [Hash](https://jsr.io/@frytg/crypto/doc/hash) (SHA-256 or SHA-512)
- [HMAC](https://jsr.io/@frytg/crypto/doc/hmac) (SHA-256 or SHA-512)
- [generate default keys](https://jsr.io/@frytg/crypto/doc/generate-default-keys)
- [generate key](https://jsr.io/@frytg/crypto/doc/generate-key)

Expand All @@ -21,7 +21,7 @@ deno run jsr:@frytg/crypto/generate-default-keys

The output will be printed to the console.

Those can be used for HMAC or encryption key generation.
Those can be used with [HMAC](https://jsr.io/@frytg/crypto/doc/hmac) or encryption key usage.
Google Cloud Storage for example uses 32 byte keys (in base64) for [customer-supplied](https://cloud.google.com/storage/docs/encryption/customer-supplied-keys) [encryption keys](https://cloud.google.com/storage/docs/encryption/using-customer-supplied-keys#storage-upload-encrypted-object-nodejs).

For SHA-256 the recommended key size is 32 bytes (256 bits) and for SHA-512 it is 64 bytes (512 bits) (see [RFC 2104](https://www.rfc-editor.org/rfc/rfc2104#section-2) - section 2 and 3).
Expand Down
10 changes: 4 additions & 6 deletions crypto/generate-key.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// deno-lint-ignore-file no-console
/**
* @module
* {@linkcode generateKey | Generate a key}
*
* This module provides a function to generate a key of the specified number of bytes and print the key in base64 and hex to the console or return the key as a Buffer.
*
* @example
* ```ts
Expand All @@ -11,9 +12,6 @@
* ```
*/

// demo provided by
// https://cloud.google.com/storage/docs/encryption/using-customer-supplied-keys#storage-generate-encryption-key-nodejs

// load packages
import type { Buffer } from 'node:buffer'
import crypto from 'node:crypto'
Expand All @@ -23,13 +21,13 @@ import crypto from 'node:crypto'
*
* @param {number} bytes - The number of bytes to generate
* @param {boolean} skipConsole - Whether to skip printing to the console
* @returns {Object} The key in base64 and hex
* @returns {Object} The key in buffer, base64 and hex
*
* @example
* ```ts
* import { generateKey } from '@frytg/crypto/generate-key'
*
* generateKey(32, true)
* generateKey(64, true)
* ```
*/
export const generateKey = (bytes = 32, skipConsole = false): { buffer: Buffer; base64: string; hex: string } => {
Expand Down

0 comments on commit e9519f1

Please sign in to comment.