jssha
- Version 3.3.1
- Published
- 624 kB
- No dependencies
- BSD-3-Clause license
Install
npm i jsshayarn add jsshapnpm add jsshaOverview
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
updatecalls (TEXT, HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.Parameter options
Options in the form of { encoding?: "UTF8" | "UTF16BE" | "UTF16LE"; numRounds?: number }.
encodingis for only TEXT input (defaults to UTF8) andnumRoundsdefaults to 1.numRoundsis not valid for any of the MAC or CSHAKE variants. * If the variant supports HMAC,optionsmay have an additionalhmacKeykey which must be in the form of {value: , format: , encoding?: "UTF8" | "UTF16BE" | "UTF16LE"} where takes the same values asinputFormatand can be astring | ArrayBuffer | Uint8Arraydepending on . Supplying this key switches to HMAC calculation and replaces the now deprecated call tosetHMACKey. * If the variant is CSHAKE128 or CSHAKE256,optionsmay have two additional keys,customizationandfuncName, which are the NIST customization and function-name strings. Both must be in the same form ashmacKey. * If the variant is KMAC128 or KMAC256,optionscan include thecustomizationkey from CSHAKE variants and *must* have akmacKeykey that takes the same form as thecustomizationkey.
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
updatecalls.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; }.
outputLenis required for variable length output variants (this option was previously calledshakeLenwhich is now deprecated).outputUpperis 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
setHMACKeycall. Now deprecated in favor of just callinggetHash.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 }.
outputUpperis only for HEX output (defaults to false) andb64padis 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
getHMACcall. Must be called immediately after jsSHA object instantiation. Now deprecated in favor of setting thehmacKeyat 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 }.
encodingis only for TEXT and defaults to UTF8.
method update
update: (input: string | ArrayBuffer | Uint8Array) => this;Takes
inputand hashes as many blocks as possible. Stores the rest for either a futureupdateorgetHashcall.Parameter input
The input to be hashed.
Returns
A reference to the object.
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (28)
- @rollup/plugin-terser
- @rollup/plugin-typescript
- @types/chai
- @types/mocha
- @types/rewire
- @types/sinon
- @typescript-eslint/eslint-plugin
- @typescript-eslint/parser
- chai
- coveralls
- eslint
- husky
- karma
- karma-chai
- karma-chrome-launcher
- karma-firefox-launcher
- karma-mocha
- lint-staged
- mocha
- nyc
- prettier
- rewire
- rollup
- rollup-plugin-dts
- sinon
- ts-node
- tslib
- typescript
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto 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[](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>
- Updated .
Package analyzed in 4286 ms. - Missing or incorrect documentation? Open an issue for this package.
