Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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);
@Lepozepo

This comment has been minimized.

Copy link

commented Jun 1, 2015

Thanks for this gist ^_^

@kkworden

This comment has been minimized.

Copy link

commented Jul 20, 2015

I hope you realized encoding something in Base64 isn't "encryption" lol

@gmale

This comment has been minimized.

Copy link

commented Aug 26, 2015

Thanks for this. I used this example inside of Postman to help to parse JSON Web Tokens from one request and pass data through to another. Worked perfectly since CryptoJS is already included 👍

@embasa

This comment has been minimized.

Copy link

commented Dec 10, 2015

Yea, It would be best if the words encrypt was changed to encode, and decrypt is changed to decode. It made me chuckle to read the word encrypt when encoding.

@albertosubero

This comment has been minimized.

Copy link

commented Apr 21, 2016

Thanks for this 👍

@cbarrerah

This comment has been minimized.

Copy link

commented Nov 17, 2016

Thanks, simple but usefull. ^.^

@umakannappan

This comment has been minimized.

Copy link

commented Mar 2, 2017

Thanks a lot

@JohnMcDaniel

This comment has been minimized.

Copy link

commented Jun 23, 2017

I also used this for a Postman test and it worked beautifully, thank you sir.

@zy723

This comment has been minimized.

Copy link

commented Jun 27, 2017

Thanks

@Niefee

This comment has been minimized.

Copy link

commented Nov 15, 2017

thinks ,i do not know why need CryptoJS.enc.Utf8.parse()?

@umeshramya

This comment has been minimized.

Copy link

commented Jan 18, 2018

this does not convert JSON object

@MichelFloyd

This comment has been minimized.

Copy link

commented Apr 3, 2018

Very helpful thank you!

@m47h4r

This comment has been minimized.

Copy link

commented Jul 23, 2019

I hope you realized encoding something in Base64 isn't "encryption" lol

The title name should be changed to prevent confusion for those who are not really familiar.

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.