2
2
import type { lib } from ' crypto-js' ;
3
3
import { MD5 , RIPEMD160 , SHA1 , SHA224 , SHA256 , SHA3 , SHA384 , SHA512 , enc } from ' crypto-js' ;
4
4
5
+ import {
6
+ adler32 ,
7
+ argon2d ,
8
+ argon2i ,
9
+ argon2id ,
10
+ blake2b ,
11
+ blake2s ,
12
+ blake3 ,
13
+ crc32 ,
14
+ crc32c ,
15
+ createSHA256 ,
16
+ keccak ,
17
+ pbkdf2 ,
18
+ sm3 ,
19
+ whirlpool ,
20
+ xxhash128 ,
21
+ xxhash3 ,
22
+ xxhash32 ,
23
+ xxhash64 ,
24
+ } from ' hash-wasm' ;
25
+
5
26
import InputCopyable from ' ../../components/InputCopyable.vue' ;
6
27
import { convertHexToBin } from ' ./hash-text.service' ;
7
- import { useQueryParam } from ' @/composable/queryParams' ;
28
+ import { useQueryParamOrStorage } from ' @/composable/queryParams' ;
8
29
9
30
const algos = {
10
31
MD5 ,
@@ -20,7 +41,27 @@ const algos = {
20
41
type AlgoNames = keyof typeof algos ;
21
42
type Encoding = keyof typeof enc | ' Bin' ;
22
43
const algoNames = Object .keys (algos ) as AlgoNames [];
23
- const encoding = useQueryParam <Encoding >({ defaultValue: ' Hex' , name: ' encoding' });
44
+
45
+ const algosWasm = {
46
+ adler32 ,
47
+ crc32 ,
48
+ crc32c ,
49
+ blake2b ,
50
+ blake2s ,
51
+ blake3 ,
52
+ keccak ,
53
+ xxhash32 ,
54
+ xxhash64 ,
55
+ xxhash3 ,
56
+ xxhash128 ,
57
+ sm3 ,
58
+ whirlpool ,
59
+ } as const ;
60
+
61
+ type AlgoWasmNames = keyof typeof algosWasm ;
62
+ const algoWasmNames = Object .keys (algosWasm ) as AlgoWasmNames [];
63
+
64
+ const encoding = useQueryParamOrStorage <Encoding >({ defaultValue: ' Hex' , storageName: ' hash-text:encoding' , name: ' encoding' });
24
65
const clearText = ref (' ' );
25
66
26
67
function formatWithEncoding(words : lib .WordArray , encoding : Encoding ) {
@@ -32,12 +73,91 @@ function formatWithEncoding(words: lib.WordArray, encoding: Encoding) {
32
73
}
33
74
34
75
const hashText = (algo : AlgoNames , value : string ) => formatWithEncoding (algos [algo ](value ), encoding .value );
76
+
77
+ const defaultHashWasmValues = {
78
+ adler32: ' ' ,
79
+ crc32: ' ' ,
80
+ crc32c: ' ' ,
81
+ blake2b: ' ' ,
82
+ blake2s: ' ' ,
83
+ blake3: ' ' ,
84
+ keccak: ' ' ,
85
+ xxhash32: ' ' ,
86
+ xxhash64: ' ' ,
87
+ xxhash3: ' ' ,
88
+ xxhash128: ' ' ,
89
+ sm3: ' ' ,
90
+ whirlpool: ' ' ,
91
+ };
92
+ const hashWasmValues = computedAsync (async () => {
93
+ const encodingValue = encoding .value ;
94
+ const clearTextValue = clearText .value ;
95
+ const ret = defaultHashWasmValues ;
96
+ for (const algo of algoWasmNames ) {
97
+ ret [algo ] = formatWithEncoding (enc .Hex .parse (await algosWasm [algo ](clearTextValue )), encodingValue );
98
+ }
99
+ return ret ;
100
+ }, defaultHashWasmValues );
101
+
102
+ const salt = new Uint8Array (16 );
103
+ window .crypto .getRandomValues (salt );
104
+ const hashWasmArgon2i = computedAsync (async () => {
105
+ const clearTextValue = clearText .value ;
106
+ return await argon2i ({
107
+ password: clearTextValue ,
108
+ salt ,
109
+ parallelism: 1 ,
110
+ memorySize: 128 ,
111
+ iterations: 4 ,
112
+ hashLength: 16 ,
113
+ outputType: ' encoded' ,
114
+ });
115
+ });
116
+ const hashWasmArgon2d = computedAsync (async () => {
117
+ const clearTextValue = clearText .value ;
118
+ return await argon2d ({
119
+ password: clearTextValue ,
120
+ salt ,
121
+ parallelism: 1 ,
122
+ memorySize: 128 ,
123
+ iterations: 4 ,
124
+ hashLength: 16 ,
125
+ outputType: ' encoded' ,
126
+ });
127
+ });
128
+ const hashWasmArgon2id = computedAsync (async () => {
129
+ const clearTextValue = clearText .value ;
130
+ return await argon2id ({
131
+ password: clearTextValue ,
132
+ salt ,
133
+ parallelism: 1 ,
134
+ memorySize: 128 ,
135
+ iterations: 4 ,
136
+ hashLength: 16 ,
137
+ outputType: ' encoded' ,
138
+ });
139
+ });
140
+ const hashWasmPBKDF2 = computedAsync (async () => {
141
+ const clearTextValue = clearText .value ;
142
+ return await pbkdf2 ({
143
+ password: clearTextValue ,
144
+ salt ,
145
+ iterations: 16 ,
146
+ hashLength: 32 ,
147
+ hashFunction: createSHA256 (),
148
+ });
149
+ });
35
150
</script >
36
151
37
152
<template >
38
153
<div >
39
154
<c-card >
40
- <c-input-text v-model:value =" clearText" multiline raw-text placeholder =" Your string to hash..." rows =" 3" autosize autofocus label =" Your text to hash:" />
155
+ <c-input-text
156
+ v-model:value =" clearText"
157
+ multiline raw-text
158
+ placeholder =" Your string to hash..." rows =" 3"
159
+ autosize autofocus label =" Your text to hash:"
160
+ />
41
161
42
162
<n-divider />
43
163
@@ -73,6 +193,44 @@ const hashText = (algo: AlgoNames, value: string) => formatWithEncoding(algos[al
73
193
<InputCopyable :value =" hashText(algo, clearText)" readonly />
74
194
</n-input-group >
75
195
</div >
196
+
197
+ <div v-for =" algo in algoWasmNames" :key =" algo" style =" margin : 5px 0 " >
198
+ <n-input-group >
199
+ <n-input-group-label style =" flex : 0 0 120px " >
200
+ {{ algo.toUpperCase() }}
201
+ </n-input-group-label >
202
+ <InputCopyable :value =" hashWasmValues[algo]" readonly />
203
+ </n-input-group >
204
+ </div >
205
+
206
+ <n-divider />
207
+
208
+ <div style =" margin : 5px 0 " >
209
+ <n-input-group >
210
+ <n-input-group-label style =" flex : 0 0 120px " >
211
+ Argon2d
212
+ </n-input-group-label >
213
+ <InputCopyable :value =" hashWasmArgon2d" readonly />
214
+ </n-input-group >
215
+ <n-input-group >
216
+ <n-input-group-label style =" flex : 0 0 120px " >
217
+ Argon2i
218
+ </n-input-group-label >
219
+ <InputCopyable :value =" hashWasmArgon2i" readonly />
220
+ </n-input-group >
221
+ <n-input-group >
222
+ <n-input-group-label style =" flex : 0 0 120px " >
223
+ Argon2id
224
+ </n-input-group-label >
225
+ <InputCopyable :value =" hashWasmArgon2id" readonly />
226
+ </n-input-group >
227
+ <n-input-group >
228
+ <n-input-group-label style =" flex : 0 0 120px " >
229
+ PBKDF2
230
+ </n-input-group-label >
231
+ <InputCopyable :value =" hashWasmPBKDF2" readonly />
232
+ </n-input-group >
233
+ </div >
76
234
</c-card >
77
235
</div >
78
236
</template >
0 commit comments