diff --git a/src/tools/encryption/encryption.vue b/src/tools/encryption/encryption.vue index 2ad47b51..42113254 100644 --- a/src/tools/encryption/encryption.vue +++ b/src/tools/encryption/encryption.vue @@ -3,16 +3,22 @@ import { AES, RC4, Rabbit, TripleDES, enc } from 'crypto-js'; import { computedCatch } from '@/composable/computed/catchedComputed'; const algos = { AES, TripleDES, Rabbit, RC4 }; +type KeyEncoding = 'Text' | 'Hex'; const cypherInput = ref('Lorem ipsum dolor sit amet'); const cypherAlgo = ref('AES'); const cypherSecret = ref('my secret key'); -const cypherOutput = computed(() => algos[cypherAlgo.value].encrypt(cypherInput.value, cypherSecret.value).toString()); +const cypherSecretEncoding = ref('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 decryptAlgo = ref('AES'); const decryptSecret = ref('my secret key'); -const [decryptOutput, decryptError] = computedCatch(() => algos[decryptAlgo.value].decrypt(decryptInput.value, decryptSecret.value).toString(enc.Utf8), { +const decryptSecretEncoding = ref('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: '', defaultErrorMessage: 'Unable to decrypt your text', }); @@ -31,6 +37,22 @@ const [decryptOutput, decryptError] = computedCatch(() => algos[decryptAlgo.valu
+ + algos[decryptAlgo.valu />
+ + {{ cypherError }} + algos[decryptAlgo.valu
+ +