Forked from joecliff/cryptojs_base64_encrypt_decrypt.js
Created
October 20, 2021 19:40
-
-
Save kafkadev/753c1d47ad94b8e3c22b5460dd048a16 to your computer and use it in GitHub Desktop.
An example of base64 usage in cryptojs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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