1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
denoland-deno/std/hash
tokiedokie 3d65177dbc
docs(std): version all imports in README (#7442)
Use $STD_VERSION in std/ README files to automatically
display proper version.
2020-10-04 14:18:36 +02:00
..
_fnv Use dprint for internal formatting (#6682) 2020-07-14 15:24:17 -04:00
_sha3 feat: update to TypeScript 4.0 (#6514) 2020-08-24 19:43:54 -04:00
_wasm chore(std/hash): update crates (#7631) 2020-09-22 23:03:11 +02:00
testdata fix(std/hash): SHA1 hash of Uint8Array (#5086) 2020-05-18 00:04:11 +02:00
fnv.ts feat: add std/hash/fnv (#5403) 2020-05-15 09:42:19 -04:00
fnv_test.ts refactor: Don't destructure the Deno namespace (#6268) 2020-06-12 15:23:38 -04:00
hasher.ts feat(std/hash): reimplement all hashes in WASM (#6292) 2020-06-16 17:12:50 -04:00
md5.ts Fix scope in std/md5 (#6662) 2020-07-06 11:28:10 -04:00
md5_test.ts refactor: Don't destructure the Deno namespace (#6268) 2020-06-12 15:23:38 -04:00
mod.ts feat: add --no-check option (#6456) 2020-07-08 11:26:39 +02:00
README.md docs(std): version all imports in README (#7442) 2020-10-04 14:18:36 +02:00
sha1.ts chore: add copyright (#7593) 2020-09-21 08:26:41 -04:00
sha1_test.ts feat(fmt): Sort named import and export specifiers (#7711) 2020-09-27 12:22:32 +02:00
sha3.ts feat: update to TypeScript 4.0 (#6514) 2020-08-24 19:43:54 -04:00
sha3_test.ts feat: update to TypeScript 4.0 (#6514) 2020-08-24 19:43:54 -04:00
sha256.ts chore: add copyright (#7593) 2020-09-21 08:26:41 -04:00
sha256_test.ts feat(fmt): Sort named import and export specifiers (#7711) 2020-09-27 12:22:32 +02:00
sha512.ts chore: add copyright (#7593) 2020-09-21 08:26:41 -04:00
sha512_test.ts feat(fmt): Sort named import and export specifiers (#7711) 2020-09-27 12:22:32 +02:00
test.ts test(std): ensure mod.ts modules have a test coverage (#7264) 2020-08-31 22:26:55 -04:00

std/hash

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