-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash.ts
executable file
·34 lines (33 loc) · 1.16 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
import { crypto, encode } from "../deps.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);
}
}