Convert string to Base64


Convert a string to Base64 using:

CLI

Use base64 to Base64 encode your string on the command-line:

$ base64 <<< 'your string'
eW91ciBzdHJpbmcK

However, this includes the newline at the end. To encode without the newline, use printf:

$ printf 'your string' | base64
eW91ciBzdHJpbmc=

For those on Mac, use pbcopy to copy the output to your clipboard:

$ printf 'your string' | base64 | pbcopy

If you don’t have base64 installed, use openssl:

$ printf 'your string' | openssl base64
eW91ciBzdHJpbmc=

Node.js

Use Buffer to convert your string to Base64 in Node.js:

$ node
> Buffer.from('your string').toString('base64')
'eW91ciBzdHJpbmc='

Or do this in one-line:

$ node -p 'Buffer.from("your string").toString("base64")'
eW91ciBzdHJpbmc=

Browser

Use btoa to encode the string in your browser’s JavaScript console:

window.btoa('your string');


Please support this site and join our Discord!