mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Merge branch 'feat/file-hasher' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # pnpm-lock.yaml # src/tools/index.ts
This commit is contained in:
commit
615cdd0779
5 files changed
+277
-1
No files matched your search
@@ -88,6 +88,7 @@
|
||||
"figlet": "^1.7.0",
|
||||
"figue": "^1.2.0",
|
||||
"fuse.js": "^6.6.2",
|
||||
"hash-wasm": "^4.11.0",
|
||||
"highlight.js": "^11.7.0",
|
||||
"iarna-toml-esm": "^3.0.5",
|
||||
"ibantools": "^4.3.3",
|
||||
@@ -96,6 +97,7 @@
|
||||
"jsbarcode": "^3.11.6",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"js-base64": "^3.7.6",
|
||||
"js-base64": "^3.7.7",
|
||||
"json5": "^2.2.3",
|
||||
"jwt-decode": "^3.1.2",
|
||||
"libphonenumber-js": "^1.10.28",
|
||||
|
||||
Generated
+9
-1
@@ -158,6 +158,9 @@ dependencies:
|
||||
fuse.js:
|
||||
specifier: ^6.6.2
|
||||
version: 6.6.2
|
||||
hash-wasm:
|
||||
specifier: ^4.11.0
|
||||
version: 4.11.0
|
||||
highlight.js:
|
||||
specifier: ^11.7.0
|
||||
version: 11.7.0
|
||||
@@ -174,7 +177,7 @@ dependencies:
|
||||
specifier: ^3.1.3
|
||||
version: 3.1.3
|
||||
js-base64:
|
||||
specifier: ^3.7.6
|
||||
specifier: ^3.7.7
|
||||
version: 3.7.7
|
||||
jsbarcode:
|
||||
specifier: ^3.11.6
|
||||
@@ -7117,6 +7120,10 @@ packages:
|
||||
safe-buffer: 5.2.1
|
||||
dev: true
|
||||
|
||||
/hash-wasm@4.11.0:
|
||||
resolution: {integrity: sha512-HVusNXlVqHe0fzIzdQOGolnFN6mX/fqcrSAOcTBXdvzrXVHwTz11vXeKRmkR5gTuwVpvHZEIyKoePDvuAR+XwQ==}
|
||||
dev: false
|
||||
|
||||
/hash.js@1.1.7:
|
||||
resolution: {integrity: sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==}
|
||||
dependencies:
|
||||
@@ -7804,6 +7811,7 @@ packages:
|
||||
/jsesc@2.5.2:
|
||||
resolution: {integrity: sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==}
|
||||
engines: {node: '>=4'}
|
||||
hasBin: true
|
||||
|
||||
/jsesc@3.0.2:
|
||||
resolution: {integrity: sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==}
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
createAdler32, // (): Promise<IHasher>
|
||||
createBLAKE2b, // (bits?: number, key?: IDataType): Promise<IHasher> // default is 512 bits
|
||||
createBLAKE2s, // (bits?: number, key?: IDataType): Promise<IHasher> // default is 256 bits
|
||||
createBLAKE3, // (bits?: number, key?: IDataType): Promise<IHasher> // default is 256 bits
|
||||
createCRC32, // (): Promise<IHasher>
|
||||
createCRC32C, // (): Promise<IHasher>
|
||||
createKeccak, // (bits?: 224 | 256 | 384 | 512): Promise<IHasher> // default is 512 bits
|
||||
createMD4, // (): Promise<IHasher>
|
||||
createMD5, // (): Promise<IHasher>
|
||||
createRIPEMD160, // (): Promise<IHasher>
|
||||
createSHA1, // (): Promise<IHasher>
|
||||
createSHA224, // (): Promise<IHasher>
|
||||
createSHA256, // (): Promise<IHasher>
|
||||
createSHA3, // (bits?: 224 | 256 | 384 | 512): Promise<IHasher> // default is 512 bits
|
||||
createSHA384, // (): Promise<IHasher>
|
||||
createSHA512, // (): Promise<IHasher>
|
||||
createSM3, // (): Promise<IHasher>
|
||||
createWhirlpool, // (): Promise<IHasher>
|
||||
// createXXHash32, //(seed: number): Promise<IHasher>
|
||||
// createXXHash64, //(seedLow: number, seedHigh: number): Promise<IHasher>
|
||||
// createXXHash3, //(seedLow: number, seedHigh: number): Promise<IHasher>
|
||||
// createXXHash128, //(seedLow: number, seedHigh: number): Promise<IHasher>
|
||||
} from 'hash-wasm';
|
||||
import type { lib } from 'crypto-js';
|
||||
import { enc } from 'crypto-js';
|
||||
|
||||
import type { IHasher } from 'hash-wasm/dist/lib/WASMInterface';
|
||||
import InputCopyable from '../../components/InputCopyable.vue';
|
||||
import { convertHexToBin } from '../hash-text/hash-text.service';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
|
||||
const status = ref<'idle' | 'done' | 'error' | 'processing'>('idle');
|
||||
const file = ref<File | null>(null);
|
||||
|
||||
async function getHashersAsync() {
|
||||
return {
|
||||
adler32: await createAdler32(), // (): Promise<IHasher>
|
||||
BLAKE2b: await createBLAKE2b(), // (bits?: number, key?: IDataType): Promise<IHasher> // default is 512 bits
|
||||
BLAKE2s: await createBLAKE2s(), // (bits?: number, key?: IDataType): Promise<IHasher> // default is 256 bits
|
||||
BLAKE3: await createBLAKE3(), // (bits?: number, key?: IDataType): Promise<IHasher> // default is 256 bits
|
||||
CRC32: await createCRC32(), // (): Promise<IHasher>
|
||||
CRC32C: await createCRC32C(), // (): Promise<IHasher>
|
||||
Keccak_224: await createKeccak(224), // (bits?: 224 | 256 | 384 | 512): Promise<IHasher> // default is 512 bits
|
||||
Keccak_256: await createKeccak(256), // (bits?: 224 | 256 | 384 | 512): Promise<IHasher> // default is 512 bits
|
||||
Keccak_384: await createKeccak(384), // (bits?: 224 | 256 | 384 | 512): Promise<IHasher> // default is 512 bits
|
||||
Keccak_512: await createKeccak(512), // (bits?: 224 | 256 | 384 | 512): Promise<IHasher> // default is 512 bits
|
||||
MD4: await createMD4(), // (): Promise<IHasher>
|
||||
MD5: await createMD5(), // (): Promise<IHasher>
|
||||
RIPEMD160: await createRIPEMD160(), // (): Promise<IHasher>
|
||||
SHA1: await createSHA1(), // (): Promise<IHasher>
|
||||
SHA224: await createSHA224(), // (): Promise<IHasher>
|
||||
SHA256: await createSHA256(), // (): Promise<IHasher>
|
||||
SHA3_224: await createSHA3(224), // (bits?: 224 | 256 | 384 | 512): Promise<IHasher> // default is 512 bits
|
||||
SHA3_256: await createSHA3(256), // (bits?: 224 | 256 | 384 | 512): Promise<IHasher> // default is 512 bits
|
||||
SHA3_384: await createSHA3(384), // (bits?: 224 | 256 | 384 | 512): Promise<IHasher> // default is 512 bits
|
||||
SHA3_512: await createSHA3(512), // (bits?: 224 | 256 | 384 | 512): Promise<IHasher> // default is 512 bits
|
||||
SHA384: await createSHA384(), // (): Promise<IHasher>
|
||||
SHA512: await createSHA512(), // (): Promise<IHasher>
|
||||
SM3: await createSM3(), // (): Promise<IHasher>
|
||||
Whirlpool: await createWhirlpool(), // (): Promise<IHasher>
|
||||
};
|
||||
}
|
||||
|
||||
const defaultHashWasmValues = {
|
||||
adler32: '',
|
||||
BLAKE2b: '',
|
||||
BLAKE2s: '',
|
||||
BLAKE3: '',
|
||||
CRC32: '',
|
||||
CRC32C: '',
|
||||
Keccak_224: '',
|
||||
Keccak_256: '',
|
||||
Keccak_384: '',
|
||||
Keccak_512: '',
|
||||
MD4: '',
|
||||
MD5: '',
|
||||
RIPEMD160: '',
|
||||
SHA1: '',
|
||||
SHA224: '',
|
||||
SHA256: '',
|
||||
SHA3_224: '',
|
||||
SHA3_256: '',
|
||||
SHA3_384: '',
|
||||
SHA3_512: '',
|
||||
SHA384: '',
|
||||
SHA512: '',
|
||||
SM3: '',
|
||||
Whirlpool: '',
|
||||
};
|
||||
const chunkSize = 64 * 1024 * 1024;
|
||||
const fileReader = new FileReader();
|
||||
|
||||
async function hashChunkAsync(chunk: Blob, hashers: IHasher[]) {
|
||||
return new Promise<void>((resolve, _reject) => {
|
||||
fileReader.onload = async (e) => {
|
||||
const view = new Uint8Array((e.target?.result as ArrayBuffer)!);
|
||||
for (const hasher of hashers) {
|
||||
hasher.update(view);
|
||||
}
|
||||
resolve();
|
||||
};
|
||||
|
||||
fileReader.readAsArrayBuffer(chunk);
|
||||
});
|
||||
}
|
||||
|
||||
type AlgoWasmNames = keyof typeof defaultHashWasmValues;
|
||||
const algoWasmNames = Object.keys(defaultHashWasmValues) as AlgoWasmNames[];
|
||||
|
||||
async function hashFileAsync(file: File) {
|
||||
const chunkNumber = Math.floor(file.size / chunkSize);
|
||||
|
||||
const hashers = await getHashersAsync();
|
||||
for (let i = 0; i <= chunkNumber; i++) {
|
||||
const chunk = file.slice(
|
||||
chunkSize * i,
|
||||
Math.min(chunkSize * (i + 1), file.size),
|
||||
);
|
||||
await hashChunkAsync(chunk, Object.values(hashers));
|
||||
}
|
||||
|
||||
const ret = { ...defaultHashWasmValues };
|
||||
for (const algo of algoWasmNames) {
|
||||
ret[algo as AlgoWasmNames] = hashers[algo as AlgoWasmNames].digest();
|
||||
}
|
||||
return Promise.resolve(ret);
|
||||
}
|
||||
|
||||
const hashes = ref(defaultHashWasmValues);
|
||||
async function onUpload(uploadedFile: File) {
|
||||
file.value = uploadedFile;
|
||||
|
||||
status.value = 'processing';
|
||||
try {
|
||||
hashes.value = await hashFileAsync(uploadedFile);
|
||||
status.value = 'done';
|
||||
}
|
||||
catch (e) {
|
||||
status.value = 'error';
|
||||
}
|
||||
}
|
||||
|
||||
type Encoding = keyof typeof enc | 'Bin';
|
||||
|
||||
const encoding = useQueryParamOrStorage<Encoding>({ defaultValue: 'Hex', storageName: 'hash-text:encoding', name: 'encoding' });
|
||||
|
||||
function formatWithEncoding(words: lib.WordArray, encoding: Encoding) {
|
||||
if (encoding === 'Bin') {
|
||||
return convertHexToBin(words.toString(enc.Hex));
|
||||
}
|
||||
|
||||
return words.toString(enc[encoding]);
|
||||
}
|
||||
|
||||
const hashWasmValues = computed(() => withDefaultOnError(() => {
|
||||
const encodingValue = encoding.value;
|
||||
const hashesValue = hashes.value;
|
||||
|
||||
const ret = defaultHashWasmValues;
|
||||
for (const algo of algoWasmNames) {
|
||||
ret[algo] = formatWithEncoding(enc.Hex.parse(hashesValue[algo]), encodingValue);
|
||||
}
|
||||
return ret;
|
||||
}, defaultHashWasmValues));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card>
|
||||
<c-file-upload
|
||||
title="Drag and drop a file here, or click to select a file"
|
||||
@file-upload="onUpload"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<c-select
|
||||
v-model:value="encoding"
|
||||
mb-4
|
||||
label="Digest encoding"
|
||||
:options="[
|
||||
{
|
||||
label: 'Binary (base 2)',
|
||||
value: 'Bin',
|
||||
},
|
||||
{
|
||||
label: 'Hexadecimal (base 16)',
|
||||
value: 'Hex',
|
||||
},
|
||||
{
|
||||
label: 'Base64 (base 64)',
|
||||
value: 'Base64',
|
||||
},
|
||||
{
|
||||
label: 'Base64url (base 64 with url safe chars)',
|
||||
value: 'Base64url',
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</c-card>
|
||||
|
||||
<div mt-3 flex justify-center>
|
||||
<c-alert v-if="status === 'error'" type="error">
|
||||
An error occured hashing file '{{ file?.name }}'.
|
||||
</c-alert>
|
||||
<n-spin
|
||||
v-if="status === 'processing'"
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<c-card v-if="status === 'done'" :title="`Hashes of ${file?.name}`">
|
||||
<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>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,38 @@
|
||||
import { EyeOff } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'File Hasher',
|
||||
path: '/file-hasher',
|
||||
description: 'Compute Hash of files',
|
||||
keywords: ['file', 'hash',
|
||||
'digest',
|
||||
'crypto',
|
||||
'security',
|
||||
'text',
|
||||
'MD5',
|
||||
'SHA1',
|
||||
'SHA256',
|
||||
'SHA224',
|
||||
'SHA512',
|
||||
'SHA384',
|
||||
'SHA3',
|
||||
'RIPEMD160',
|
||||
'ADLER32',
|
||||
'BLAKE2B',
|
||||
'BLAKE2S',
|
||||
'BLAKE3',
|
||||
'CRC32',
|
||||
'CRC32C',
|
||||
'KECCAK',
|
||||
'PBKDF2',
|
||||
'SM3',
|
||||
'WHIRLPOOL',
|
||||
'XXHASH128',
|
||||
'XXHASH3',
|
||||
'XXHASH32',
|
||||
'XXHASH64'],
|
||||
component: () => import('./file-hasher.vue'),
|
||||
icon: EyeOff,
|
||||
createdAt: new Date('2024-05-11'),
|
||||
});
|
||||
@@ -9,6 +9,7 @@ import { tool as colorWheel } from './color-wheel';
|
||||
import { tool as currencyConverter } from './currency-converter';
|
||||
import { tool as emailParser } from './email-parser';
|
||||
import { tool as outlookParser } from './outlook-parser';
|
||||
import { tool as fileHasher } from './file-hasher';
|
||||
|
||||
import { tool as cssXpathConverter } from './css-xpath-converter';
|
||||
import { tool as cssSelectorsMemo } from './css-selectors-memo';
|
||||
@@ -119,6 +120,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
tokenGenerator,
|
||||
hashText,
|
||||
crcCalculator,
|
||||
fileHasher,
|
||||
bcrypt,
|
||||
uuidGenerator,
|
||||
ulidGenerator,
|
||||
|
||||
Reference in new issue
Block a user