https://github.com/brix/crypto-js
I successfully installed CryptoJS using npm i crypto-js.
However, I am facing difficulty in integrating it into my project. When I attempt to use the following code:
// Decrypt
var bytes = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');
var originalText = bytes.toString(CryptoJS.enc.Utf8);
console.log(originalText);
An error message pops up saying that CryptoJS is undefined in my code snippet shown below:
<script>
import CryptoJS from 'crypto-js'
require('crypto-js')
export default {
name: "AnswerQuestionnaire",
components:{
},
props: {
},
data() {
return {
}
},
created(){
this.CryptoJS.AES.decrypt("zU5jEPwQSm2P0X33jgH6sg==", "sB7b5q4fp0G59R9t").toString(this.CryptoJS.enc.Utf8)
},
mounted(){
}
};
The specific error message reads as follows:
VM820424:1 Uncaught ReferenceError: CryptoJs is not defined
at eval (eval at created