Hierarchy

  • NodeCryptoSha2Hash

Constructors

Properties

Methods

Constructors

  • Parameters

    • createHash: ((algorithm, options?) => Hash)
        • (algorithm, options?): Hash
        • Creates and returns a Hash object that can be used to generate hash digests using the given algorithm. Optional options argument controls stream behavior. For XOF hash functions such as 'shake256', the outputLength option can be used to specify the desired output length in bytes.

          The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha256', 'sha512', etc. On recent releases of OpenSSL, openssl list -digest-algorithms will display the available digest algorithms.

          Example: generating the sha256 sum of a file

          import {
          createReadStream
          } from 'fs';
          import { argv } from 'process';
          const {
          createHash
          } = await import('crypto');

          const filename = argv[2];

          const hash = createHash('sha256');

          const input = createReadStream(filename);
          input.on('readable', () => {
          // Only one element is going to be produced by the
          // hash stream.
          const data = input.read();
          if (data)
          hash.update(data);
          else {
          console.log(`${hash.digest('hex')} ${filename}`);
          }
          });

          Parameters

          • algorithm: string
          • Optional options: HashOptions

            stream.transform options

          Returns Hash

          Since

          v0.1.92

    Returns NodeCryptoSha2Hash

Properties

createHash: ((algorithm, options?) => Hash)

Type declaration

    • (algorithm, options?): Hash
    • Creates and returns a Hash object that can be used to generate hash digests using the given algorithm. Optional options argument controls stream behavior. For XOF hash functions such as 'shake256', the outputLength option can be used to specify the desired output length in bytes.

      The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha256', 'sha512', etc. On recent releases of OpenSSL, openssl list -digest-algorithms will display the available digest algorithms.

      Example: generating the sha256 sum of a file

      import {
      createReadStream
      } from 'fs';
      import { argv } from 'process';
      const {
      createHash
      } = await import('crypto');

      const filename = argv[2];

      const hash = createHash('sha256');

      const input = createReadStream(filename);
      input.on('readable', () => {
      // Only one element is going to be produced by the
      // hash stream.
      const data = input.read();
      if (data)
      hash.update(data);
      else {
      console.log(`${hash.digest('hex')} ${filename}`);
      }
      });

      Parameters

      • algorithm: string
      • Optional options: HashOptions

        stream.transform options

      Returns Hash

      Since

      v0.1.92

Methods

  • Parameters

    • data: Uint8Array
    • algorithm: string = 'sha256'

    Returns Promise<Uint8Array>

Generated using TypeDoc