std/hash
2021-07-01 14:26:56 +09:00
..
_fnv update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
_sha3 update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
_wasm feat(hash): add BLAKE3 hash support (#994) 2021-07-01 14:26:56 +09:00
testdata fix(hash): SHA1 hash of Uint8Array (denoland/deno#5086) 2021-02-01 10:46:57 +00:00
fnv_test.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
fnv.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
hasher.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
md5_test.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
md5.ts refactor(md5): throw TypeError for wrong type (#698) 2021-02-08 22:35:53 -05:00
mod.ts feat(hash): add BLAKE3 hash support (#994) 2021-07-01 14:26:56 +09:00
README.md feat(hash): add BLAKE3 hash support (#994) 2021-07-01 14:26:56 +09:00
sha1_test.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
sha1.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
sha3_test.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
sha3.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
sha256_test.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
sha256.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
sha512_test.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
sha512.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
test.ts feat(hash): add BLAKE3 hash support (#994) 2021-07-01 14:26:56 +09:00

std/hash

hash is module to provide interfaces for hash functions.

Usage

Creating new hash instance

You can create a new Hasher instance by calling createHash defined in mod.ts.

import { createHash } from "https://deno.land/std@$STD_VERSION/hash/mod.ts";

const hash = createHash("md5");
// ...

Using hash instance

You can use update method to feed data into your hash instance. Call digest method to retrive final hash value in ArrayBuffer.

import { createHash } from "https://deno.land/std@$STD_VERSION/hash/mod.ts";

const hash = createHash("md5");
hash.update("Your data here");
const final = hash.digest(); // returns ArrayBuffer.

Please note that digest invalidates the hash instance's internal state. Calling digest more than once will throw an Error.

import { createHash } from "https://deno.land/std@$STD_VERSION/hash/mod.ts";

const hash = createHash("md5");
hash.update("Your data here");
const final1 = hash.digest(); // returns ArrayBuffer.
const final2 = hash.digest(); // throws Error.

If you need final hash in string formats, call toString method with output format.

Supported formats are hex and base64 and default format is hex.

import { createHash } from "https://deno.land/std@$STD_VERSION/hash/mod.ts";

const hash = createHash("md5");
hash.update("Your data here");
const hashInHex = hash.toString(); // returns 5fe084ee423ff7e0c7709e9437cee89d
import { createHash } from "https://deno.land/std@$STD_VERSION/hash/mod.ts";

const hash = createHash("md5");
hash.update("Your data here");
const hashInBase64 = hash.toString("base64"); // returns X+CE7kI/9+DHcJ6UN87onQ==

Supported algorithms

Following algorithms are supported.

  • md2
  • md4
  • md5
  • ripemd160
  • ripemd320
  • sha1
  • sha224
  • sha256
  • sha384
  • sha512
  • sha3-224
  • sha3-256
  • sha3-384
  • sha3-512
  • keccak224
  • keccak256
  • keccak384
  • keccak512
  • blake3