Base64 Encoding and Decoding from Command Line

Learn how to encode and decode strings in Base64 from your command line. This guide covers practical steps for Windows, Linux, Mac, and different shells.
On this page

Base64 Encoding and Decoding from Command Line

Excerpt

If you want to encode or decode a string to Base64 from your command line, there are some simple steps to follow. Here are some practical ways to achieve this on different operating systems and shells.

Encoding String to Base64

Encoding in Windows

  1. Open your command prompt.

  2. Type the following command, replacing input_file and output_file with your desired inputs and outputs:

    1certutil -encode input_file output_file
    

    For example, to encode a string, you can use the following command:

    1echo -n "IToolkit" | certutil -encode -
    

Encoding in Linux

  1. Open your terminal.

  2. Type the following command, replacing input_file and output_file with your desired inputs and outputs:

    1base64 input_file -w 0 > output_file
    

    For example, to encode a string, you can use the following command:

    1echo -n "IToolkit" | base64
    

Encoding in Mac

  1. Open your terminal.

  2. Type the following command, replacing input_file and output_file with your desired inputs and outputs:

    1base64 -i input_file -o output_file
    

    For example, to encode a string, you can use the following command:

    1echo -n "IToolkit" | base64
    

Encoding in Shell

  1. Open your shell.

  2. Type the following command, replacing input_file and output_file with your desired inputs and outputs:

    1openssl enc -base64 -in input_file -out output_file
    

    For example, to encode a string, you can use the following command:

    1echo -n "IToolkit" | openssl enc -base64
    

The free Base64 Encode verification tool is as follows:

Decoding Base64 to String

Decoding in Windows

  1. Open your command prompt.

  2. Type the following command, replacing input_file and output_file with your desired inputs and outputs:

    1certutil -decode input_file output_file
    

    For example, to decode a string, you can use the following command:

    1echo -n "SVRvb2xraXQ=" | certutil -decodehex -
    

Decoding in Linux

  1. Open your terminal.

  2. Type the following command, replacing input_file and output_file with your desired inputs and outputs:

    1base64 -d input_file -w 0 > output_file
    

    For example, to decode a string, you can use the following command:

    1echo -n "SVRvb2xraXQ=" | base64 -d
    

Decoding in Mac

  1. Open your terminal.

  2. Type the following command, replacing input_file and output_file with your desired inputs and outputs:

    1base64 -D -i input_file -o output_file
    

    For example, to decode a string, you can use the following command:

    1echo -n "SVRvb2xraXQ=" | base64 -D
    

Decoding in Shell

  1. Open your shell.

  2. Type the following command, replacing input_file and output_file with your desired inputs and outputs:

    1openssl enc -base64 -d -in input_file -out output_file
    

    For example, to decode a string, you can use the following command:

    1echo -n "SVRvb2xraXQ=" | openssl enc -base64 -d
    

The free Base64 Decode verification tool is as follows:

Precautions when Using

  • Be careful with sensitive information; Base64 is not encryption.
  • Always double-check if you typed the correct syntax for your command.
  • Don’t forget to check if the output is correct.

In conclusion, encoding and decoding from Base64 in the command line is a practical skill that is useful in various contexts. By following these simple steps, you can easily encode and decode strings in Base64. Just be sure to follow the noted precautions to avoid any potential issues.