jssha

  • Version 3.2.0
  • Published
  • 605 kB
  • No dependencies
  • BSD-3-Clause license

Install

npm i jssha
yarn add jssha
pnpm add jssha

Overview

jsSHA implements the complete Secure Hash Standard (SHA) family (SHA-1, SHA-224/256/384/512, SHA3-224/256/384/512, SHAKE128/256, cSHAKE128/256, and KMAC128/256) with HMAC

Index

Classes

class jsSHA

class jsSHA {}

    constructor

    constructor(
    variant: FixedLengthVariantType,
    inputFormat: string,
    options?: FixedLengthOptionsEncodingType
    );
    • Parameter variant

      The desired SHA variant (SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA3-224, SHA3-256, SHA3-256, SHA3-384, SHA3-512, SHAKE128, SHAKE256, CSHAKE128, CSHAKE256, KMAC128, or KMAC256) as a string.

      Parameter inputFormat

      The input format to be used in future update calls (TEXT, HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.

      Parameter options

      Options in the form of { encoding?: "UTF8" | "UTF16BE" | "UTF16LE"; numRounds?: number }. encoding is for only TEXT input (defaults to UTF8) and numRounds defaults to 1. numRounds is not valid for any of the MAC or CSHAKE variants. * If the variant supports HMAC, options may have an additional hmacKey key which must be in the form of {value: , format: , encoding?: "UTF8" | "UTF16BE" | "UTF16LE"} where takes the same values as inputFormat and can be a string | ArrayBuffer | Uint8Array depending on . Supplying this key switches to HMAC calculation and replaces the now deprecated call to setHMACKey. * If the variant is CSHAKE128 or CSHAKE256, options may have two additional keys, customization and funcName, which are the NIST customization and function-name strings. Both must be in the same form as hmacKey. * If the variant is KMAC128 or KMAC256, options can include the customization key from CSHAKE variants and *must* have a kmacKey key that takes the same form as the customization key.

    constructor

    constructor(
    variant: FixedLengthVariantType,
    inputFormat: FormatNoTextType,
    options?: FixedLengthOptionsNoEncodingType
    );

      constructor

      constructor(
      variant: 'SHAKE128' | 'SHAKE256',
      inputFormat: string,
      options?: SHAKEOptionsEncodingType
      );

        constructor

        constructor(
        variant: 'SHAKE128' | 'SHAKE256',
        inputFormat: FormatNoTextType,
        options?: SHAKEOptionsNoEncodingType
        );

          constructor

          constructor(
          variant: 'CSHAKE128' | 'CSHAKE256',
          inputFormat: string,
          options?: CSHAKEOptionsEncodingType
          );

            constructor

            constructor(
            variant: 'CSHAKE128' | 'CSHAKE256',
            inputFormat: FormatNoTextType,
            options?: CSHAKEOptionsNoEncodingType
            );

              constructor

              constructor(
              variant: 'KMAC128' | 'KMAC256',
              inputFormat: string,
              options: KMACOptionsEncodingType
              );

                constructor

                constructor(
                variant: 'KMAC128' | 'KMAC256',
                inputFormat: FormatNoTextType,
                options: KMACOptionsNoEncodingType
                );

                  method getHash

                  getHash: {
                  (
                  format: 'HEX',
                  options?: {
                  outputUpper?: boolean;
                  outputLen?: number;
                  shakeLen?: number;
                  }
                  ): string;
                  (
                  format: 'B64',
                  options?: { b64Pad?: string; outputLen?: number; shakeLen?: number }
                  ): string;
                  (
                  format: 'BYTES',
                  options?: { outputLen?: number; shakeLen?: number }
                  ): string;
                  (
                  format: 'UINT8ARRAY',
                  options?: { outputLen?: number; shakeLen?: number }
                  ): Uint8Array;
                  (
                  format: 'ARRAYBUFFER',
                  options?: { outputLen?: number; shakeLen?: number }
                  ): ArrayBuffer;
                  };
                  • Returns the desired SHA or MAC (if a HMAC/KMAC key was specified) hash of the input fed in via update calls.

                    Parameter format

                    The desired output formatting (B64, HEX, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.

                    Parameter options

                    Options in the form of { outputUpper?: boolean; b64Pad?: string; outputLen?: number; }. outputLen is required for variable length output variants (this option was previously called shakeLen which is now deprecated). outputUpper is only for HEX output (defaults to false) and b64pad is only for B64 output (defaults to "=").

                    Returns

                    The hash in the format specified.

                  method getHMAC

                  getHMAC: {
                  (format: 'HEX', options?: { outputUpper?: boolean }): string;
                  (format: 'B64', options?: { b64Pad?: string }): string;
                  (format: 'BYTES'): string;
                  (format: 'UINT8ARRAY'): Uint8Array;
                  (format: 'ARRAYBUFFER'): ArrayBuffer;
                  };
                  • Returns the the HMAC in the specified format using the key given by a previous setHMACKey call. Now deprecated in favor of just calling getHash.

                    Parameter format

                    The desired output formatting (B64, HEX, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.

                    Parameter options

                    Options in the form of { outputUpper?: boolean; b64Pad?: string }. outputUpper is only for HEX output (defaults to false) and b64pad is only for B64 output (defaults to "=").

                    Returns

                    The HMAC in the format specified.

                  method setHMACKey

                  setHMACKey: {
                  (
                  key: string,
                  inputFormat: 'TEXT',
                  options?: { encoding?: EncodingType }
                  ): void;
                  (key: string, inputFormat: 'HEX' | 'B64' | 'BYTES'): void;
                  (key: ArrayBuffer, inputFormat: 'ARRAYBUFFER'): void;
                  (key: Uint8Array, inputFormat: 'UINT8ARRAY'): void;
                  };
                  • Sets the HMAC key for an eventual getHMAC call. Must be called immediately after jsSHA object instantiation. Now deprecated in favor of setting the hmacKey at object instantiation.

                    Parameter key

                    The key used to calculate the HMAC

                    Parameter inputFormat

                    The format of key (HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.

                    Parameter options

                    Options in the form of { encoding?: "UTF8" | "UTF16BE" | "UTF16LE }. encoding is only for TEXT and defaults to UTF8.

                  method update

                  update: (input: string | ArrayBuffer | Uint8Array) => void;
                  • Takes input and hashes as many blocks as possible. Stores the rest for either a future update or getHash call.

                    Parameter input

                    The input to be hashed

                  Package Files (1)

                  Dependencies (0)

                  No dependencies.

                  Dev Dependencies (28)

                  Peer Dependencies (0)

                  No peer dependencies.

                  Badge

                  To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                  You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/jssha.

                  • Markdown
                    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/jssha)
                  • HTML
                    <a href="https://www.jsdocs.io/package/jssha"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>