mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-20 14:56:17 -04:00
Merge 4fd536a5ff
into 07eea0f484
This commit is contained in:
commit
c795cf2dfb
1 changed files with 43 additions and 2 deletions
|
@ -3,16 +3,22 @@ import { AES, RC4, Rabbit, TripleDES, enc } from 'crypto-js';
|
||||||
import { computedCatch } from '@/composable/computed/catchedComputed';
|
import { computedCatch } from '@/composable/computed/catchedComputed';
|
||||||
|
|
||||||
const algos = { AES, TripleDES, Rabbit, RC4 };
|
const algos = { AES, TripleDES, Rabbit, RC4 };
|
||||||
|
type KeyEncoding = 'Text' | 'Hex';
|
||||||
|
|
||||||
const cypherInput = ref('Lorem ipsum dolor sit amet');
|
const cypherInput = ref('Lorem ipsum dolor sit amet');
|
||||||
const cypherAlgo = ref<keyof typeof algos>('AES');
|
const cypherAlgo = ref<keyof typeof algos>('AES');
|
||||||
const cypherSecret = ref('my secret key');
|
const cypherSecret = ref('my secret key');
|
||||||
const cypherOutput = computed(() => algos[cypherAlgo.value].encrypt(cypherInput.value, cypherSecret.value).toString());
|
const cypherSecretEncoding = ref<KeyEncoding>('Text');
|
||||||
|
const [cypherOutput, cypherError] = computedCatch(() => algos[cypherAlgo.value].encrypt(cypherInput.value, cypherSecretEncoding.value === 'Text' ? cypherSecret.value : enc.Hex.parse(cypherSecret.value), { iv: enc.Hex.parse('') }).toString(), {
|
||||||
|
defaultValue: '',
|
||||||
|
defaultErrorMessage: 'Unable to cypher your text',
|
||||||
|
});
|
||||||
|
|
||||||
const decryptInput = ref('U2FsdGVkX1/EC3+6P5dbbkZ3e1kQ5o2yzuU0NHTjmrKnLBEwreV489Kr0DIB+uBs');
|
const decryptInput = ref('U2FsdGVkX1/EC3+6P5dbbkZ3e1kQ5o2yzuU0NHTjmrKnLBEwreV489Kr0DIB+uBs');
|
||||||
const decryptAlgo = ref<keyof typeof algos>('AES');
|
const decryptAlgo = ref<keyof typeof algos>('AES');
|
||||||
const decryptSecret = ref('my secret key');
|
const decryptSecret = ref('my secret key');
|
||||||
const [decryptOutput, decryptError] = computedCatch(() => algos[decryptAlgo.value].decrypt(decryptInput.value, decryptSecret.value).toString(enc.Utf8), {
|
const decryptSecretEncoding = ref<KeyEncoding>('Text');
|
||||||
|
const [decryptOutput, decryptError] = computedCatch(() => algos[decryptAlgo.value].decrypt(decryptInput.value, decryptSecretEncoding.value === 'Text' ? decryptSecret.value : enc.Hex.parse(decryptSecret.value), { iv: enc.Hex.parse('') }).toString(enc.Utf8), {
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
defaultErrorMessage: 'Unable to decrypt your text',
|
defaultErrorMessage: 'Unable to decrypt your text',
|
||||||
});
|
});
|
||||||
|
@ -31,6 +37,22 @@ const [decryptOutput, decryptError] = computedCatch(() => algos[decryptAlgo.valu
|
||||||
<div flex flex-1 flex-col gap-2>
|
<div flex flex-1 flex-col gap-2>
|
||||||
<c-input-text v-model:value="cypherSecret" label="Your secret key:" clearable raw-text />
|
<c-input-text v-model:value="cypherSecret" label="Your secret key:" clearable raw-text />
|
||||||
|
|
||||||
|
<c-select
|
||||||
|
v-model:value="cypherSecretEncoding" label="Key encoding"
|
||||||
|
flex-1
|
||||||
|
placeholder="Select the key encoding..."
|
||||||
|
:options="[
|
||||||
|
{
|
||||||
|
label: 'Plain Text',
|
||||||
|
value: 'Text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Hexadecimal Text',
|
||||||
|
value: 'Hex',
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
|
||||||
<c-select
|
<c-select
|
||||||
v-model:value="cypherAlgo"
|
v-model:value="cypherAlgo"
|
||||||
label="Encryption algorithm:"
|
label="Encryption algorithm:"
|
||||||
|
@ -38,6 +60,9 @@ const [decryptOutput, decryptError] = computedCatch(() => algos[decryptAlgo.valu
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<c-alert v-if="cypherError" type="error" mt-12 title="Error while cyphering">
|
||||||
|
{{ cypherError }}
|
||||||
|
</c-alert>
|
||||||
<c-input-text
|
<c-input-text
|
||||||
label="Your text encrypted:"
|
label="Your text encrypted:"
|
||||||
:value="cypherOutput"
|
:value="cypherOutput"
|
||||||
|
@ -58,6 +83,22 @@ const [decryptOutput, decryptError] = computedCatch(() => algos[decryptAlgo.valu
|
||||||
<div flex flex-1 flex-col gap-2>
|
<div flex flex-1 flex-col gap-2>
|
||||||
<c-input-text v-model:value="decryptSecret" label="Your secret key:" clearable raw-text />
|
<c-input-text v-model:value="decryptSecret" label="Your secret key:" clearable raw-text />
|
||||||
|
|
||||||
|
<c-select
|
||||||
|
v-model:value="decryptSecretEncoding" label="Key encoding"
|
||||||
|
flex-1
|
||||||
|
placeholder="Select the key encoding..."
|
||||||
|
:options="[
|
||||||
|
{
|
||||||
|
label: 'Plain Text',
|
||||||
|
value: 'Text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Hexadecimal Text',
|
||||||
|
value: 'Hex',
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
|
||||||
<c-select
|
<c-select
|
||||||
v-model:value="decryptAlgo"
|
v-model:value="decryptAlgo"
|
||||||
label="Encryption algorithm:"
|
label="Encryption algorithm:"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue