Encrypt File Using Crypto JS in Aura Component

cryptojs

We want to encrypt the input file on client side using javascript in our aura component.

We are trying to use CryptoJS(https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js).

We have added this JS library as static resource and added in lightning component.

This library is working fine in Visualforce page. But in aura lightning component, we are getting error says "CryptoJS is not defined" when we call below method.

CryptoJS.AES.encrypt('123', '1234567887654321');

Same method is working fine in the VF page. Any idea why?

Best Answer

Use the file 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js' instead of only aes.js file. May be aes.js internally dowloads all dependencies when you are using inside VF Page and that's how it is working inside VF Page.

enter image description here

Related Topic