Base64 encoding and decoding

How to do base64 encoding?

Using Javascript

How to encode?

  1. Use chrome
  2. Go to More tools -> Developer tools -> Console
    console.log(btoa("string that needs to be encoded"))
    
  3. Grab the encoded value from the output.

How to decode?

atob()

Reading material:

  1. https://developer.mozilla.org/en-US/docs/Web/API/atob
  2. https://developer.mozilla.org/en-US/docs/Web/API/btoa

Using terminal in Linux

(This method seems to be including some additional text after the base64 encoded string. Use the chrome method.)

How to encode?

$ echo 'text that needs to be encoded' > file.txt
$ base64 file.txt

How to decode?

echo 'encodedTxthjggyjhkhkhk' | base64 -d

Links to this note