diff --git a/crypto/README.md b/crypto/README.md index ac78996..24e7c16 100644 --- a/crypto/README.md +++ b/crypto/README.md @@ -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) @@ -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). diff --git a/crypto/generate-key.ts b/crypto/generate-key.ts index 7a910ac..28e1357 100644 --- a/crypto/generate-key.ts +++ b/crypto/generate-key.ts @@ -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 @@ -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' @@ -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 } => {