it-tools/src/tools/encryption/encryption.vue

100 lines
3.2 KiB
Vue
Raw Normal View History

2022-04-07 22:13:09 +02:00
<template>
<c-card title="Encrypt">
<n-space item-style="flex: 1 1 0">
<n-form-item label="Your text:" :show-feedback="false">
2022-04-15 23:10:47 +02:00
<n-input
v-model:value="cypherInput"
2022-04-15 23:10:47 +02:00
type="textarea"
placeholder="The string to cypher"
:autosize="{ minRows: 4 }"
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
2022-04-15 23:10:47 +02:00
/>
</n-form-item>
<n-space vertical>
<c-input-text v-model:value="cypherSecret" label="Your secret key:" clearable raw-text />
<n-form-item label="Encryption algorithm:" :show-feedback="false">
<n-select
v-model:value="cypherAlgo"
:options="Object.keys(algos).map((label) => ({ label, value: label }))"
2022-04-15 23:10:47 +02:00
/>
</n-form-item>
</n-space>
</n-space>
<n-form-item label="Your text encrypted:" :show-feedback="false" mt-5>
<n-input
:value="cypherOutput"
type="textarea"
placeholder="Your string hash"
:autosize="{ minRows: 2 }"
readonly
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
/>
</n-form-item>
</c-card>
<c-card title="Decrypt">
<n-space item-style="flex: 1 1 0">
<n-form-item label="Your encrypted text:" :show-feedback="false">
2022-04-15 23:10:47 +02:00
<n-input
v-model:value="decryptInput"
2022-04-15 23:10:47 +02:00
type="textarea"
placeholder="The string to cypher"
:autosize="{ minRows: 4 }"
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
2022-04-15 23:10:47 +02:00
/>
</n-form-item>
<n-space vertical>
<c-input-text v-model:value="decryptSecret" label="Your secret key:" clearable raw-text />
<n-form-item label="Encryption algorithm:" :show-feedback="false">
<n-select
v-model:value="decryptAlgo"
:options="Object.keys(algos).map((label) => ({ label, value: label }))"
/>
</n-form-item>
</n-space>
</n-space>
<n-form-item label="Your decrypted text:" :show-feedback="false" mt-5>
<n-input
:value="decryptOutput"
type="textarea"
placeholder="Your string hash"
:autosize="{ minRows: 2 }"
readonly
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
/>
</n-form-item>
</c-card>
2022-04-07 22:13:09 +02:00
</template>
<script setup lang="ts">
2022-04-22 23:31:40 +02:00
import { computed, ref } from 'vue';
import { AES, TripleDES, Rabbit, RC4, enc } from 'crypto-js';
2022-04-07 22:13:09 +02:00
2022-04-22 23:31:40 +02:00
const algos = { AES, TripleDES, Rabbit, RC4 };
2022-04-07 22:13:09 +02:00
2022-04-22 23:31:40 +02:00
const cypherInput = ref('Lorem ipsum dolor sit amet');
const cypherAlgo = ref<keyof typeof algos>('AES');
const cypherSecret = ref('my secret key');
const cypherOutput = computed(() => algos[cypherAlgo.value].encrypt(cypherInput.value, cypherSecret.value).toString());
2022-04-07 22:13:09 +02:00
2022-04-22 23:31:40 +02:00
const decryptInput = ref('U2FsdGVkX1/EC3+6P5dbbkZ3e1kQ5o2yzuU0NHTjmrKnLBEwreV489Kr0DIB+uBs');
const decryptAlgo = ref<keyof typeof algos>('AES');
const decryptSecret = ref('my secret key');
const decryptOutput = computed(() =>
algos[decryptAlgo.value].decrypt(decryptInput.value, decryptSecret.value).toString(enc.Utf8),
);
2022-04-07 22:13:09 +02:00
</script>