Merge branch 'feat/hash-text-enh' into chore/all-my-stuffs

# Conflicts:
#	pnpm-lock.yaml
This commit is contained in:
ShareVB committed 2024-11-03 20:31:37 +01:00
commit fe419958e4
3 files changed
+182 -6

No files matched your search

+1 -2
View File
@@ -4545,7 +4545,7 @@ packages:
/@vueuse/shared@10.0.0(vue@3.3.4):
resolution: {integrity: sha512-Zh3LgJqvUBWVY3SiMvXanTcfAneGbt63QPczBRDNgQ6jd/ehodO9a1lCFzaA6SWJJoI+ugVTjHFYJdoR656DVQ==}
dependencies:
vue-demi: 0.14.10(vue@3.3.4)
vue-demi: 0.14.5(vue@3.3.4)
transitivePeerDependencies:
- '@vue/composition-api'
- vue
@@ -11652,7 +11652,6 @@ packages:
/yamljs@0.3.0:
resolution: {integrity: sha512-C/FsVVhht4iPQYXOInoxUM/1ELSf9EsgKH34FofQOp6hwCPrW4vG4w5++TED3xRUo8gD7l0P1J1dLlDYzODsTQ==}
hasBin: true
dependencies:
argparse: 1.0.10
glob: 7.2.3
+161 -3
View File
@@ -2,9 +2,30 @@
import type { lib } from 'crypto-js';
import { MD5, RIPEMD160, SHA1, SHA224, SHA256, SHA3, SHA384, SHA512, enc } from 'crypto-js';
import {
adler32,
argon2d,
argon2i,
argon2id,
blake2b,
blake2s,
blake3,
crc32,
crc32c,
createSHA256,
keccak,
pbkdf2,
sm3,
whirlpool,
xxhash128,
xxhash3,
xxhash32,
xxhash64,
} from 'hash-wasm';
import InputCopyable from '../../components/InputCopyable.vue';
import { convertHexToBin } from './hash-text.service';
import { useQueryParam } from '@/composable/queryParams';
import { useQueryParamOrStorage } from '@/composable/queryParams';
const algos = {
MD5,
@@ -20,7 +41,27 @@ const algos = {
type AlgoNames = keyof typeof algos;
type Encoding = keyof typeof enc | 'Bin';
const algoNames = Object.keys(algos) as AlgoNames[];
const encoding = useQueryParam<Encoding>({ defaultValue: 'Hex', name: 'encoding' });
const algosWasm = {
adler32,
crc32,
crc32c,
blake2b,
blake2s,
blake3,
keccak,
xxhash32,
xxhash64,
xxhash3,
xxhash128,
sm3,
whirlpool,
} as const;
type AlgoWasmNames = keyof typeof algosWasm;
const algoWasmNames = Object.keys(algosWasm) as AlgoWasmNames[];
const encoding = useQueryParamOrStorage<Encoding>({ defaultValue: 'Hex', storageName: 'hash-text:encoding', name: 'encoding' });
const clearText = ref('');
function formatWithEncoding(words: lib.WordArray, encoding: Encoding) {
@@ -32,12 +73,91 @@ function formatWithEncoding(words: lib.WordArray, encoding: Encoding) {
}
const hashText = (algo: AlgoNames, value: string) => formatWithEncoding(algos[algo](value), encoding.value);
const defaultHashWasmValues = {
adler32: '',
crc32: '',
crc32c: '',
blake2b: '',
blake2s: '',
blake3: '',
keccak: '',
xxhash32: '',
xxhash64: '',
xxhash3: '',
xxhash128: '',
sm3: '',
whirlpool: '',
};
const hashWasmValues = computedAsync(async () => {
const encodingValue = encoding.value;
const clearTextValue = clearText.value;
const ret = defaultHashWasmValues;
for (const algo of algoWasmNames) {
ret[algo] = formatWithEncoding(enc.Hex.parse(await algosWasm[algo](clearTextValue)), encodingValue);
}
return ret;
}, defaultHashWasmValues);
const salt = new Uint8Array(16);
window.crypto.getRandomValues(salt);
const hashWasmArgon2i = computedAsync(async () => {
const clearTextValue = clearText.value;
return await argon2i({
password: clearTextValue,
salt,
parallelism: 1,
memorySize: 128,
iterations: 4,
hashLength: 16,
outputType: 'encoded',
});
});
const hashWasmArgon2d = computedAsync(async () => {
const clearTextValue = clearText.value;
return await argon2d({
password: clearTextValue,
salt,
parallelism: 1,
memorySize: 128,
iterations: 4,
hashLength: 16,
outputType: 'encoded',
});
});
const hashWasmArgon2id = computedAsync(async () => {
const clearTextValue = clearText.value;
return await argon2id({
password: clearTextValue,
salt,
parallelism: 1,
memorySize: 128,
iterations: 4,
hashLength: 16,
outputType: 'encoded',
});
});
const hashWasmPBKDF2 = computedAsync(async () => {
const clearTextValue = clearText.value;
return await pbkdf2({
password: clearTextValue,
salt,
iterations: 16,
hashLength: 32,
hashFunction: createSHA256(),
});
});
</script>
<template>
<div>
<c-card>
<c-input-text v-model:value="clearText" multiline raw-text placeholder="Your string to hash..." rows="3" autosize autofocus label="Your text to hash:" />
<c-input-text
v-model:value="clearText"
multiline raw-text
placeholder="Your string to hash..." rows="3"
autosize autofocus label="Your text to hash:"
/>
<n-divider />
@@ -73,6 +193,44 @@ const hashText = (algo: AlgoNames, value: string) => formatWithEncoding(algos[al
<InputCopyable :value="hashText(algo, clearText)" readonly />
</n-input-group>
</div>
<div v-for="algo in algoWasmNames" :key="algo" style="margin: 5px 0">
<n-input-group>
<n-input-group-label style="flex: 0 0 120px">
{{ algo.toUpperCase() }}
</n-input-group-label>
<InputCopyable :value="hashWasmValues[algo]" readonly />
</n-input-group>
</div>
<n-divider />
<div style="margin: 5px 0">
<n-input-group>
<n-input-group-label style="flex: 0 0 120px">
Argon2d
</n-input-group-label>
<InputCopyable :value="hashWasmArgon2d" readonly />
</n-input-group>
<n-input-group>
<n-input-group-label style="flex: 0 0 120px">
Argon2i
</n-input-group-label>
<InputCopyable :value="hashWasmArgon2i" readonly />
</n-input-group>
<n-input-group>
<n-input-group-label style="flex: 0 0 120px">
Argon2id
</n-input-group-label>
<InputCopyable :value="hashWasmArgon2id" readonly />
</n-input-group>
<n-input-group>
<n-input-group-label style="flex: 0 0 120px">
PBKDF2
</n-input-group-label>
<InputCopyable :value="hashWasmPBKDF2" readonly />
</n-input-group>
</div>
</c-card>
</div>
</template>
+20 -1
View File
@@ -5,7 +5,8 @@ import { translate } from '@/plugins/i18n.plugin';
export const tool = defineTool({
name: translate('tools.hash-text.title'),
path: '/hash-text',
description: translate('tools.hash-text.description'),
description:
'Hash a text string using the function you need : MD5, SHA1, SHA256, SHA224, SHA512, SHA384, SHA3, RIPEMD160, ADLER32, CRC32, CRC32C, BLAKE, KECCAK, XXHASH, SM3, WHIRLPOOL or Argon2(i/d/id)',
keywords: [
'hash',
'digest',
@@ -20,6 +21,24 @@ export const tool = defineTool({
'SHA384',
'SHA3',
'RIPEMD160',
'ADLER32',
'BLAKE2B',
'BLAKE2S',
'BLAKE3',
'CRC32',
'CRC32C',
'KECCAK',
'PBKDF2',
'SM3',
'WHIRLPOOL',
'XXHASH128',
'XXHASH3',
'XXHASH32',
'XXHASH64',
'Argon2',
'Argon2i',
'Argon2d',
'Argon2id',
],
component: () => import('./hash-text.vue'),
icon: EyeOff,