diff options
author | 2023-11-01 11:11:51 +0100 | |
---|---|---|
committer | 2023-11-01 10:11:51 +0000 | |
commit | 02b0d0d1a13cb8bcbf7f98339278fd874a0cbc19 (patch) | |
tree | 7ecbf28e38d9382811d63d39ea76649ed72dc5c1 /src/tools/encryption/encryption.vue | |
parent | 4d5a67d96d68e8c7ce790cf95f34c8c15736845e (diff) | |
download | it-tools-02b0d0d1a13cb8bcbf7f98339278fd874a0cbc19.tar.gz it-tools-02b0d0d1a13cb8bcbf7f98339278fd874a0cbc19.tar.zst it-tools-02b0d0d1a13cb8bcbf7f98339278fd874a0cbc19.zip |
fix(encryption): alert on decryption error (#711)
* update(c-alert): Add variant 'error'
* fix(encryption): Alert decryption error (#652)
* feat(c-alert): added title
* refactor(composable): mutualized computedCatch
---------
Co-authored-by: code2933 <code2933@outlook.com>
Diffstat (limited to 'src/tools/encryption/encryption.vue')
-rw-r--r-- | src/tools/encryption/encryption.vue | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/tools/encryption/encryption.vue b/src/tools/encryption/encryption.vue index 4a348f8..2ad47b5 100644 --- a/src/tools/encryption/encryption.vue +++ b/src/tools/encryption/encryption.vue @@ -1,5 +1,6 @@ <script setup lang="ts"> import { AES, RC4, Rabbit, TripleDES, enc } from 'crypto-js'; +import { computedCatch } from '@/composable/computed/catchedComputed'; const algos = { AES, TripleDES, Rabbit, RC4 }; @@ -11,9 +12,10 @@ const cypherOutput = computed(() => algos[cypherAlgo.value].encrypt(cypherInput. 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), -); +const [decryptOutput, decryptError] = computedCatch(() => algos[decryptAlgo.value].decrypt(decryptInput.value, decryptSecret.value).toString(enc.Utf8), { + defaultValue: '', + defaultErrorMessage: 'Unable to decrypt your text', +}); </script> <template> @@ -63,7 +65,11 @@ const decryptOutput = computed(() => /> </div> </div> + <c-alert v-if="decryptError" type="error" mt-12 title="Error while decrypting"> + {{ decryptError }} + </c-alert> <c-input-text + v-else label="Your decrypted text:" :value="decryptOutput" placeholder="Your string hash" |