Skip to content

Instantly share code, notes, and snippets.

@jhuamanchumo
Last active October 14, 2021 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhuamanchumo/87d8dc3db7ead46a7312bf5c020992cf to your computer and use it in GitHub Desktop.
Save jhuamanchumo/87d8dc3db7ead46a7312bf5c020992cf to your computer and use it in GitHub Desktop.
AES Encryption - JavaScript
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>
</head>
<body>
<script>
var plain = 'hola';
var encrypted = '+u9j05H2X3pUa2eYVdVXyA==';
var secretKey = CryptoJS.enc.Utf8.parse('secretKey');
var vectorInit = CryptoJS.enc.Utf8.parse('vectorInit');
var options = {mode: CryptoJS.mode.CBC, iv:vectorInit, padding: CryptoJS.pad.Pkcs7};
//Encrypt
var encrypted = CryptoJS.AES.encrypt(plain, secretKey, options);
console.log("encrypted: " + encrypted.toString());
//Decrypt
var decrypted = CryptoJS.AES.decrypt(encrypted, secretKey, options);
console.log("decrypted: " + CryptoJS.enc.Utf8.stringify(decrypted));
</script>
</body>
</html>
----------------------------------------------------------------------------------
https://jsbin.com/rigezuy/edit?html,console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment