std/hash
Skye 4d43706106
CI: Add License header check (#2292)
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
2022-06-01 13:49:12 +02:00
..
_fnv refactor: mark modules as browser compatible (#1972) 2022-03-01 13:25:50 +09:00
_sha3 refactor: replace TS private with private identifiers (#2272) 2022-05-27 21:27:13 +09:00
_wasm CI: Add License header check (#2292) 2022-06-01 13:49:12 +02:00
testdata fix(hash): SHA1 hash of Uint8Array (denoland/deno#5086) 2021-02-01 10:46:57 +00:00
fnv_test.ts chore: update copyright header (#1871) 2022-02-02 23:21:39 +09:00
fnv.ts refactor: mark modules as browser compatible (#1972) 2022-03-01 13:25:50 +09:00
hasher.ts refactor: mark modules as browser compatible (#1972) 2022-03-01 13:25:50 +09:00
md5_test.ts chore: update copyright header (#1871) 2022-02-02 23:21:39 +09:00
md5.ts refactor: replace TS private with private identifiers (#2272) 2022-05-27 21:27:13 +09:00
mod.ts docs: add module level docs (#2190) 2022-05-04 19:34:37 +09:00
README.md chore: deprecate std/hash (#1350) 2021-10-06 12:01:31 +09:00
sha1_test.ts chore: update copyright header (#1871) 2022-02-02 23:21:39 +09:00
sha1.ts refactor: replace TS private with private identifiers (#2272) 2022-05-27 21:27:13 +09:00
sha3_test.ts chore: update copyright header (#1871) 2022-02-02 23:21:39 +09:00
sha3.ts refactor: mark modules as browser compatible (#1972) 2022-03-01 13:25:50 +09:00
sha256_test.ts chore: update copyright header (#1871) 2022-02-02 23:21:39 +09:00
sha256.ts chore: update code format (#2278) 2022-05-27 21:26:01 +09:00
sha512_test.ts chore: update copyright header (#1871) 2022-02-02 23:21:39 +09:00
sha512.ts chore: update code format (#2278) 2022-05-27 21:26:01 +09:00
test.ts refactor: switch the Deno.spawn (#2161) 2022-05-25 11:08:27 +02:00

std/hash is deprecated

std/hash is deprecated now. Use Web Crypto API or std/crypto instead.


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 retrieve 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