Function generateKeySync

  • Synchronously generates a new random secret key of the given length. Thetype will determine which validations will be performed on the length.

    const {
    generateKeySync
    } = await import('crypto');

    const key = generateKeySync('hmac', { length: 64 });
    console.log(key.export().toString('hex')); // e89..........41e

    Parameters

    • type: "hmac" | "aes"

      The intended use of the generated secret key. Currently accepted values are 'hmac' and 'aes'.

    • options: { length: number }
      • length: number

    Returns "crypto".KeyObject

  • Synchronously generates a new random secret key of the given length. Thetype will determine which validations will be performed on the length.

    const {
    generateKeySync
    } = await import('crypto');

    const key = generateKeySync('hmac', { length: 64 });
    console.log(key.export().toString('hex')); // e89..........41e

    Parameters

    • type: "hmac" | "aes"

      The intended use of the generated secret key. Currently accepted values are 'hmac' and 'aes'.

    • options: { length: number }
      • length: number

    Returns "crypto".KeyObject

Generated using TypeDoc