1
0
Fork 0
mirror of https://github.com/CorentinTh/it-tools.git synced 2025-07-27 09:09:37 +02:00
it-tools/src/tools/hash-text/hash-text.vue

55 lines
1.4 KiB
Vue
Raw Normal View History

2022-04-04 00:25:53 +02:00
<template>
2022-04-15 23:10:47 +02:00
<div>
<n-card>
2022-04-22 23:31:40 +02:00
<n-input v-model:value="clearText" type="textarea" placeholder="Your string..." :autosize="{ minRows: 3 }" />
<br />
<br />
<n-select v-model:value="algo" :options="Object.keys(algos).map((label) => ({ label, value: label }))" />
2022-04-04 00:25:53 +02:00
2022-04-22 23:31:40 +02:00
<br />
2022-04-15 23:10:47 +02:00
<n-input
2022-04-22 23:31:40 +02:00
style="text-align: center"
2022-04-15 23:10:47 +02:00
:value="hashedText"
type="textarea"
placeholder="Your string hash"
:autosize="{ minRows: 1 }"
readonly
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
/>
2022-04-22 23:31:40 +02:00
<br />
<br />
2022-04-15 23:10:47 +02:00
<n-space justify="center">
2022-04-22 23:31:40 +02:00
<n-button secondary autofocus @click="copy"> Copy </n-button>
2022-04-15 23:10:47 +02:00
</n-space>
</n-card>
</div>
2022-04-04 00:25:53 +02:00
</template>
<script setup lang="ts">
import { useCopy } from '@/composable/copy';
2022-04-22 23:31:40 +02:00
import { ref, computed } from 'vue';
import { MD5, SHA1, SHA256, SHA224, SHA512, SHA384, SHA3, RIPEMD160 } from 'crypto-js';
2022-04-04 00:25:53 +02:00
const algos = {
2022-04-22 23:31:40 +02:00
MD5,
SHA1,
SHA256,
SHA224,
SHA512,
SHA384,
SHA3,
RIPEMD160,
2022-04-04 00:25:53 +02:00
} as const;
2022-04-22 23:31:40 +02:00
const clearText = ref(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lacus metus blandit dolor lacus natoque ad fusce aliquam velit.',
);
const algo = ref<keyof typeof algos>('SHA256');
const hashedText = computed(() => algos[algo.value](clearText.value).toString());
2022-04-04 00:25:53 +02:00
2022-04-22 23:31:40 +02:00
const { copy } = useCopy({ source: hashedText, text: 'Hash copied to the clipboard' });
2022-04-04 00:25:53 +02:00
</script>