diff --git a/src/tools/encryption/encryption.vue b/src/tools/encryption/encryption.vue index d4f6e34a..bd4bef4d 100644 --- a/src/tools/encryption/encryption.vue +++ b/src/tools/encryption/encryption.vue @@ -22,6 +22,13 @@ :options="Object.keys(algos).map((label) => ({ label, value: label }))" /> + + + @@ -61,6 +68,13 @@ :options="Object.keys(algos).map((label) => ({ label, value: label }))" /> + + + @@ -85,15 +99,29 @@ import { AES, TripleDES, Rabbit, RC4, enc } from 'crypto-js'; const algos = { AES, TripleDES, Rabbit, RC4 }; -const cypherInput = ref('Lorem ipsum dolor sit amet'); +const cypherInput = ref('Hello World!'); const cypherAlgo = ref('AES'); -const cypherSecret = ref('my secret key'); -const cypherOutput = computed(() => algos[cypherAlgo.value].encrypt(cypherInput.value, cypherSecret.value).toString()); +const cypherSecret = ref('16bit secret key'); +const cypherInitializationVector = ref('1234567812345678'); +const cypherOutput = computed(() => { + var cfg = {}; + if (cypherAlgo.value === 'AES' || cypherAlgo.value === 'TripleDES') { + cfg = { iv: enc.Utf8.parse(cypherInitializationVector.value) }; + } + return algos[cypherAlgo.value].encrypt(cypherInput.value, enc.Utf8.parse(cypherSecret.value), cfg).toString(); +}); -const decryptInput = ref('U2FsdGVkX1/EC3+6P5dbbkZ3e1kQ5o2yzuU0NHTjmrKnLBEwreV489Kr0DIB+uBs'); +const decryptInput = ref('DX+W8WBHbt08XoJNV8bcoQ=='); const decryptAlgo = ref('AES'); -const decryptSecret = ref('my secret key'); -const decryptOutput = computed(() => - algos[decryptAlgo.value].decrypt(decryptInput.value, decryptSecret.value).toString(enc.Utf8), -); +const decryptSecret = ref('16bit secret key'); +const decryptInitializationVector = ref('1234567812345678'); +const decryptOutput = computed(() => { + var cfg = {}; + if (decryptAlgo.value === 'AES' || decryptAlgo.value === 'TripleDES') { + cfg = { iv: enc.Utf8.parse(decryptInitializationVector.value) }; + } + return algos[decryptAlgo.value] + .decrypt(decryptInput.value, enc.Utf8.parse(decryptSecret.value), cfg) + .toString(enc.Utf8); +});