Last active
June 17, 2018 20:57
-
-
Save JokingChicken/0c5ce03085bcd78c3d81f87a9a63a8a6 to your computer and use it in GitHub Desktop.
Base64 Encoding and Decoding in Node
This file contains 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
//Here is how you encode normal text to base64 in Node.js: | |
var b = new Buffer('JavaScript'); | |
var s = b.toString('base64'); | |
// SmF2YVNjcmlwdA== | |
//And here is how you decode base64 encoded strings: | |
var b = new Buffer('SmF2YVNjcmlwdA==', 'base64') | |
var s = b.toString(); | |
// JavaScript | |
//Let's encode a base64 encoded string to hex: | |
var b = new Buffer('SmF2YVNjcmlwdA==', 'base64') | |
var s = b.toString('hex'); | |
// 4a617661536372697074 | |
//Now decode it to something humans can read: | |
var b = new Buffer('4a617661536372697074', 'hex') | |
var s = b.toString('utf8'); | |
// JavaScript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment