1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
<template>
<div>
<n-card>
<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 }))"
/>
<br />
<n-input
style="text-align: center;"
:value="hashedText"
type="textarea"
placeholder="Your string hash"
:autosize="{ minRows: 1 }"
readonly
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
/>
<br />
<br />
<n-space justify="center">
<n-button @click="copy" secondary autofocus>Copy</n-button>
</n-space>
</n-card>
</div>
</template>
<script setup lang="ts">
import { useCopy } from '@/composable/copy';
import { ref, computed } from 'vue'
import {
MD5,
SHA1,
SHA256,
SHA224,
SHA512,
SHA384,
SHA3,
RIPEMD160,
} from 'crypto-js'
const algos = {
MD5,
SHA1,
SHA256,
SHA224,
SHA512,
SHA384,
SHA3,
RIPEMD160,
} as const;
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())
const { copy } = useCopy({ source: hashedText, text: 'Hash copied to the clipboard' })
</script>
<style lang="less" scoped>
</style>
|