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?

1 Answer 1


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

  • 1
    This worked. Thanks so much. Commented Feb 21, 2022 at 11:24
  • Hi both,I am also stuck with same issue like "AES is not defined" . Do we need to load both JS files in LWC ? whats the approach you used. Can you please share the code snippet here. Commented Sep 15, 2023 at 21:04
  • You can try browserify module to create a single js to use inside LWC Component.
    – Saroj Bera
    Commented Sep 18, 2023 at 10:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .