Simple AES in JavaScript - Part II

By John Keyes

July 2, 2024 at 13:38

javascript javascript encryption aes

In the Simple AES in JavaScript - Part I post I described how to use CryptoJS to implement AES string encryption.

However, when running the tests for the Cloudfalre Worker code this didn’t work due to the module being referenced via require rather than import.

To workaround this I moved to the CryptoES module (originally forked from CryptoJS), which provides ES6 support.

Install dependency

crypto-es is required:

npm install crypto-es

Change from require to import

Then change:

const cryptoJS = require('crypto-js');

to:

import CryptoES from 'crypto-es';
const cryptoJS = CryptoES;

References

Last updated: July 2, 2024 at 13:38