Function generateKey

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

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

    generateKey('hmac', { length: 64 }, (err, key) => {
    if (err) throw err;
    console.log(key.export().toString('hex')); // 46e..........620
    });

    Parameters

    • type: "hmac" | "aes"

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

    • options: { length: number }
      • length: number
    • callback: ((err: Error, key: "crypto".KeyObject) => void)

    Returns void

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

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

    generateKey('hmac', { length: 64 }, (err, key) => {
    if (err) throw err;
    console.log(key.export().toString('hex')); // 46e..........620
    });

    Parameters

    • type: "hmac" | "aes"

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

    • options: { length: number }
      • length: number
    • callback: ((err: Error, key: "crypto".KeyObject) => void)

    Returns void

Generated using TypeDoc