Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save synsa/9ae00c5b2e0a4e17ff6e4bf419f28db6 to your computer and use it in GitHub Desktop.
Save synsa/9ae00c5b2e0a4e17ff6e4bf419f28db6 to your computer and use it in GitHub Desktop.
An example of base64 usage in cryptojs
var CryptoJS = require("crypto-js");//replace thie with script tag in browser env
//encrypt
var rawStr = "hello world!";
var wordArray = CryptoJS.enc.Utf8.parse(rawStr);
var base64 = CryptoJS.enc.Base64.stringify(wordArray);
console.log('encrypted:', base64);
//decrypt
var parsedWordArray = CryptoJS.enc.Base64.parse(base64);
var parsedStr = parsedWordArray.toString(CryptoJS.enc.Utf8);
console.log("parsed:",parsedStr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment