-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash.ts
executable file
·37 lines (36 loc) · 1.26 KB
/
hash.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { crypto } from "https://deno.land/std@0.173.0/crypto/mod.ts";
import {
encode,
} from "https://deno.land/std@0.173.0/encoding/base64.ts";
export class hash {
static async sha256(str: string): Promise<string> {
const encoder = new TextEncoder();
const data = encoder.encode(str);
const hash = await crypto.subtle.digest("SHA-256", data);
return encode(hash);
}
static async sha512(str: string): Promise<string> {
const encoder = new TextEncoder();
const data = encoder.encode(str);
const hash = await crypto.subtle.digest("SHA-512", data);
return encode(hash);
}
static async sha384(str: string): Promise<string> {
const encoder = new TextEncoder();
const data = encoder.encode(str);
const hash = await crypto.subtle.digest("SHA-384", data);
return encode(hash);
}
static async sha3_256(str: string): Promise<string> {
const encoder = new TextEncoder();
const data = encoder.encode(str);
const hash = await crypto.subtle.digest("SHA3-256", data);
return encode(hash);
}
static async sha3_512(str: string): Promise<string> {
const encoder = new TextEncoder();
const data = encoder.encode(str);
const hash = await crypto.subtle.digest("SHA3-512", data);
return encode(hash);
}
}