Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
CryptoJS AES encryption/decryption JavaScript and command line examples

You can run these commands to encrypt or decrypt a string:


To encrypt:

printf "Lorem ipsum dolor sit amet, ..." | \
  openssl enc -e -base64 -A -aes-256-cbc -pass pass:"my-password"

To decrypt:

printf "U2FsdGVkX1/l/LqNSCQixd0iPv4neKAGZvbQDbYUovZE4OcM7l3ULNDgkZQmrweN" | \
  openssl enc -d -base64 -A -aes-256-cbc -pass pass:"my-password"

Note: Other users can see your text content and password in commands above.


To encrypt:

echo Text to encrypt:; read STRING; \
printf "Password: "; read -s PASS; \
echo; echo Encrypted:; printf "$STRING" | \
openssl enc -e -base64 -A -aes-256-cbc -pass pass:"$PASS"

To decrypt:

echo Encrypted text:; read STRING; \
printf "Password: "; read -s PASS; \
echo; echo Decrypted:; printf "$STRING" | \
openssl enc -d -base64 -A -aes-256-cbc -pass pass:"$PASS"


You can open console of your browser, copy and run these commands to use CryptoJS:

var s=document.createElement('script');

You can use CryptoJS AES once the script is loaded:

CryptoJS.AES.encrypt("Lorem ipsum dolor sit amet, ...", "my-password").toString();
<script src=""></script>
var string = 'Lorem ipsum dolor sit amet, ...';
var password = 'my-password';
var encrypted = CryptoJS.AES.encrypt(string, password);
// will output something like:
// U2FsdGVkX1/l/LqNSCQixd0iPv4neKAGZvbQDbYUovZE4OcM7l3ULNDgkZQmrweN
var decrypted = CryptoJS.AES.decrypt(encrypted, password);
// Lorem ipsum dolor sit amet, ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.