visit
Bash is a Unix shell and command language. These bash commands are widely used in Mac OS X and Unix-like operating systems for interacting with the system via commands. Bash also has a utility command, Base64
, for encoding and decoding data.
This tutorial teaches you the different methods to decode Base64 data into a file in Unix-like operating systems using commands and online tools.
The command, with the flag --decode
, decodes the base64 data into a string.
-d
parameter. It’ll decode base64 encoded data>
and pass the file name with an extension. You need to pass the correct extension of the file equivalent to the Base64 string. Otherwise, the output file will be corrupted due to the incorrect extension
Important: Ensure you have write access to the current working directory needed to create the new output file.
Code
base64 -d <<< "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" > image.png
openssl base64
command with the -d
parameter-out
parameter and pass the file name with an extension. You need to pass the correct extension of the file equivalent to the Base64 string
Important: Ensure you have write access to the current working directory needed to create the new output file.
Code
$ openssl base64 -d <<< "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" -out image.png
.txt
file and upload it to the decoder tool
The main advantage of using the online Base64 decoder tool is you do not need to know the extension of the file types. For example, the image file can be in different formats such as .jpg
, .png
or a .gif
. The online tool will detect the file extension automatically based on the input string and create a file equivalent to the string with the proper file extension.