2023-05-28 23:13:24 +02:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { AES, RC4, Rabbit, TripleDES, enc } from 'crypto-js';
|
|
|
|
|
|
|
|
const algos = { AES, TripleDES, Rabbit, RC4 };
|
2023-10-22 14:09:49 +08:00
|
|
|
const { t } = useI18n();
|
|
|
|
const cypherInput = ref(t('tools.encryption.encrypt.text.default'));
|
2023-05-28 23:13:24 +02:00
|
|
|
const cypherAlgo = ref<keyof typeof algos>('AES');
|
2023-10-22 14:09:49 +08:00
|
|
|
const cypherSecret = ref(t('tools.encryption.encrypt.secretKey.default'));
|
2023-05-28 23:13:24 +02:00
|
|
|
const cypherOutput = computed(() => algos[cypherAlgo.value].encrypt(cypherInput.value, cypherSecret.value).toString());
|
|
|
|
|
2023-10-22 14:09:49 +08:00
|
|
|
const decryptInput = ref(t('tools.encryption.decrypt.encrypted.default'));
|
2023-05-28 23:13:24 +02:00
|
|
|
const decryptAlgo = ref<keyof typeof algos>('AES');
|
2023-10-22 14:09:49 +08:00
|
|
|
const decryptSecret = ref(t('tools.encryption.decrypt.secretKey.default'));
|
2023-05-28 23:13:24 +02:00
|
|
|
const decryptOutput = computed(() =>
|
|
|
|
algos[decryptAlgo.value].decrypt(decryptInput.value, decryptSecret.value).toString(enc.Utf8),
|
|
|
|
);
|
|
|
|
</script>
|
|
|
|
|
2022-04-07 22:13:09 +02:00
|
|
|
<template>
|
2023-04-20 20:49:28 +02:00
|
|
|
<c-card title="Encrypt">
|
2023-05-27 17:36:15 +02:00
|
|
|
<div flex gap-3>
|
2023-06-25 15:00:50 +02:00
|
|
|
<c-input-text
|
|
|
|
v-model:value="cypherInput"
|
2023-10-22 14:09:49 +08:00
|
|
|
:label="`${t('tools.encryption.encrypt.text.label')}: `"
|
|
|
|
:placeholder="t('tools.encryption.encrypt.text.placeholder')"
|
2023-06-25 15:00:50 +02:00
|
|
|
rows="4"
|
|
|
|
multiline raw-text monospace autosize flex-1
|
|
|
|
/>
|
2023-05-27 17:36:15 +02:00
|
|
|
<div flex flex-1 flex-col gap-2>
|
2023-10-22 14:09:49 +08:00
|
|
|
<c-input-text v-model:value="cypherSecret" :label="`${t('tools.encryption.encrypt.secretKey.label')}:`" clearable raw-text />
|
2023-05-14 21:26:18 +02:00
|
|
|
|
2023-08-07 17:30:00 +02:00
|
|
|
<c-select
|
|
|
|
v-model:value="cypherAlgo"
|
2023-10-22 14:09:49 +08:00
|
|
|
:label="`${t('tools.encryption.encrypt.algorithm.label')}:`"
|
2023-08-07 17:30:00 +02:00
|
|
|
:options="Object.keys(algos).map((label) => ({ label, value: label }))"
|
|
|
|
/>
|
2023-05-27 17:36:15 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-06-25 15:00:50 +02:00
|
|
|
<c-input-text
|
2023-10-22 14:09:49 +08:00
|
|
|
:label="`${t('tools.encryption.encrypt.encrypted.label')}:`"
|
2023-06-25 15:00:50 +02:00
|
|
|
:value="cypherOutput"
|
|
|
|
rows="3"
|
2023-10-22 14:09:49 +08:00
|
|
|
:placeholder="t('tools.encryption.encrypt.encrypted.placeholder')"
|
2023-06-25 15:00:50 +02:00
|
|
|
multiline monospace readonly autosize mt-5
|
|
|
|
/>
|
2023-04-20 20:49:28 +02:00
|
|
|
</c-card>
|
|
|
|
<c-card title="Decrypt">
|
2023-05-27 17:36:15 +02:00
|
|
|
<div flex gap-3>
|
2023-06-25 15:00:50 +02:00
|
|
|
<c-input-text
|
|
|
|
v-model:value="decryptInput"
|
2023-10-22 14:09:49 +08:00
|
|
|
:label="`${t('tools.encryption.decrypt.encrypted.label')}:`"
|
|
|
|
:placeholder="t('tools.encryption.decrypt.encrypted.placeholder')"
|
2023-06-25 15:00:50 +02:00
|
|
|
rows="4"
|
|
|
|
multiline raw-text monospace autosize flex-1
|
|
|
|
/>
|
2023-05-27 17:36:15 +02:00
|
|
|
<div flex flex-1 flex-col gap-2>
|
2023-10-22 14:09:49 +08:00
|
|
|
<c-input-text v-model:value="decryptSecret" :label="`${t('tools.encryption.decrypt.secretKey.label')}:`" clearable raw-text />
|
2023-05-14 21:26:18 +02:00
|
|
|
|
2023-08-07 17:30:00 +02:00
|
|
|
<c-select
|
|
|
|
v-model:value="decryptAlgo"
|
2023-10-22 14:09:49 +08:00
|
|
|
:label="`${t('tools.encryption.decrypt.algorithm.label')}:`"
|
2023-08-07 17:30:00 +02:00
|
|
|
:options="Object.keys(algos).map((label) => ({ label, value: label }))"
|
|
|
|
/>
|
2023-05-27 17:36:15 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-06-25 15:00:50 +02:00
|
|
|
<c-input-text
|
2023-10-22 14:09:49 +08:00
|
|
|
:label="`${t('tools.encryption.decrypt.text.label')}:`"
|
2023-06-25 15:00:50 +02:00
|
|
|
:value="decryptOutput"
|
2023-10-22 14:09:49 +08:00
|
|
|
:placeholder="t('tools.encryption.decrypt.text.placeholder')"
|
2023-06-25 15:00:50 +02:00
|
|
|
rows="3"
|
|
|
|
multiline monospace readonly autosize mt-5
|
|
|
|
/>
|
2023-04-20 20:49:28 +02:00
|
|
|
</c-card>
|
2022-04-07 22:13:09 +02:00
|
|
|
</template>
|