diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f66d5855..eb8813d7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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 diff --git a/src/tools/hash-text/hash-text.vue b/src/tools/hash-text/hash-text.vue index 6eae9818..c6466f20 100644 --- a/src/tools/hash-text/hash-text.vue +++ b/src/tools/hash-text/hash-text.vue @@ -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({ 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({ 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(), + }); +}); diff --git a/src/tools/hash-text/index.ts b/src/tools/hash-text/index.ts index 2070e41d..d214cf97 100644 --- a/src/tools/hash-text/index.ts +++ b/src/tools/hash-text/index.ts @@ -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,