deno.land / std@0.160.0 / hash
std/hash
is deprecated now. Use Web Crypto API or std/crypto instead.
hash is module to provide interfaces for hash functions.
You can create a new Hasher instance by calling createHash
defined in mod.ts.
import { createHash } from "https://deno.land/std@0.160.0/hash/mod.ts";
const hash = createHash("md5");
// ...
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@0.160.0/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@0.160.0/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@0.160.0/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@0.160.0/hash/mod.ts";
const hash = createHash("md5");
hash.update("Your data here");
const hashInBase64 = hash.toString("base64"); // returns X+CE7kI/9+DHcJ6UN87onQ==
Following algorithms are supported.
Version Info