Skip to content

hash.js

James ZHANG edited this page Jan 16, 2022 · 4 revisions

Classes

Hash

Crypto hash functions utils. Specification

Constants

md5
hex
sha256
sha1
MD5
HMAC-SHA256

Hash

Crypto hash functions utils. Specification

Kind: global class

Hash.md5(thing, [key], [agency]) ⇒ string

Calculate the input string with an optional secret key in MD5, when the key is Falsey, this method works as normal MD5.

  • [agency] is available {@since v0.4.3}, spec

Kind: static method of Hash
Returns: string - - data signature

Param Type Default Description
thing string | Buffer The input string.
[key] string The secret key string.
[agency] boolean | number | string false The secret key is from wework, placed with true or better of the AgentId value.

Hash.hmac(thing, key, [algorithm]) ⇒ string

Calculate the input string with a secret key as of algorithm string which is one of the 'sha256', 'sha512' etc.

Kind: static method of Hash
Returns: string - - data signature

Param Type Default Description
thing string | Buffer The input string.
key string The secret key string.
[algorithm] string "sha256" The algorithm string, default is sha256.

Hash.hmacSha256(thing, key) ⇒ string

Deprecated

Kind: static method of Hash
Returns: string - - data signature

Param Type Description
thing string | Buffer The input string.
key string The secret key string.

Hash.sha1(thing) ⇒ string

Calculate the input in SHA1.

Kind: static method of Hash
Returns: string - - data signature

Param Type Description
thing string | Buffer The input.

Hash.sha256(thing) ⇒ string

Calculate the input in SHA256.

Kind: static method of Hash
Returns: string - - data signature

Param Type Description
thing string | Buffer The input.

Hash.equals(known, [user]) ⇒ boolean

Wrapping the builtins crypto.timingSafeEqual function.

Kind: static method of Hash
Returns: boolean - - Returns true when the two are equal, false otherwise.

Param Type Description
known string The string of known length to compare against.
[user] string The user-supplied string.

Hash.sign(type, data, key) ⇒ string

Utils of the data signature calculation.

Kind: static method of Hash
Returns: string - - The data signature.

Param Type Description
type string The sign type, one of the MD5 or HMAC-SHA256.
data object The input data.
key string The secret key string.

md5

Kind: global constant

hex

Kind: global constant

sha256

Kind: global constant

sha1

Kind: global constant

MD5

Kind: global constant

HMAC-SHA256

Kind: global constant