1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/std/hash
Ryan Dahl d0970daacd
make std deno-lint clean (#6240)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2020-06-12 09:19:29 -04:00
..
_fnv feat: add std/hash/fnv (#5403) 2020-05-15 09:42:19 -04:00
_sha3 feat(std/hash): add sha3 (#5558) 2020-06-04 15:14:36 -04: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 feat: add std/hash/fnv (#5403) 2020-05-15 09:42:19 -04:00
md5.ts make std deno-lint clean (#6240) 2020-06-12 09:19:29 -04:00
md5_test.ts feat(std/hash): add md5 (#5719) 2020-05-21 12:39:32 -04:00
README.md readme for std/hash (#6139) 2020-06-06 12:36:34 -04:00
sha1.ts fix(std/hash): SHA1 hash of Uint8Array (#5086) 2020-05-18 00:04:11 +02:00
sha1_test.ts Migrate from dprint-ignore to deno-fmt-ignore (#5659) 2020-05-27 14:21:18 +02:00
sha3.ts feat(std/hash): add sha3 (#5558) 2020-06-04 15:14:36 -04:00
sha3_test.ts feat(std/hash): add sha3 (#5558) 2020-06-04 15:14:36 -04:00
sha256.ts Migrate from dprint-ignore to deno-fmt-ignore (#5659) 2020-05-27 14:21:18 +02:00
sha256_test.ts Migrate from dprint-ignore to deno-fmt-ignore (#5659) 2020-05-27 14:21:18 +02:00
sha512.ts feat(std/hash): add Sha512 and HmacSha512 (#6009) 2020-05-31 16:03:37 -04:00
sha512_test.ts feat(std/hash): add Sha512 and HmacSha512 (#6009) 2020-05-31 16:03:37 -04:00

std/hash

MD5

Uses:

import { Md5 } from "https://deno.land/std/hash/md5.ts";

const md5 = new Md5();
const md5Instance = md5.update("中文"); // return instance of `Md5`
console.log(md5Instance instanceof Md5); // true
console.log(md5Instance.toString()); // a7bac2239fcdcb3a067903d8077c4a07

Calling update method, It will update internal state based on the input provided. Once you call md5Instance.toString(), it will return the hash string. You can provide format as hash or base64. The default format is hex.

sample:

console.log(md5Instance.toString("base64")); // MNgWOD+FHGO3Fff/HDCY2w==

SHA1

Uses:

Creating sha1 hash is simple. You can use Sha1 class instance and update the digest. Calling hex method will return the sha1 in hex value. You can also use toString method.

import { Sha1 } from "https://deno.land/std/hash/sha1.ts";

const sha1 = new Sha1().update("中文");
console.log(sha1.hex()); // 7be2d2d20c106eee0836c9bc2b939890a78e8fb3
console.log(sha1.toString()); // same as above

Sha256 and HmacSha256

Uses:

Creating Sha256 hash is simple. You can use Sha256 class instance and update the digest. Calling the hex method will return the sha256 in hex value. You can also use the toString method.

Note: For HmacSha256, you can pass the secret key while creating an instance of the object.

import { Sha256, HmacSha256 } from "https://deno.land/std/hash/sha256.ts";

const sha256 = new Sha256().update("中文");
console.log(sha256.hex());
console.log(sha256.toString()); // Same as above

const key = "Hi There";
const hmac = new HmacSha256(key).update("中文");

console.log(hmac.hex());
console.log(hmac.toString()); // Same as above