Overview
`openssl base64` is part of the `openssl` toolkit and provides Base64 encoding and decoding capabilities. This feature is useful for converting data into a text format, enhancing compatibility across various systems. It is particularly common when transmitting binary files (images, archives, etc.) over text-based protocols (HTTP, SMTP, etc.).
Key Features
- Encode data from a file or standard input (stdin)
- Output encoded/decoded data to a file or standard output (stdout)
- Encode to Base64 format
- Decode from Base64 format to original data
Key Options
These are the main options used with the `openssl base64` command.
Input/Output and Operation
Generated command:
Try combining the commands.
Description:
`openssl` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Practical examples of using the `openssl base64` command.
Encode a String to Base64
echo -n "Hello World" | openssl base64
Encodes the string 'Hello World' to Base64 using standard input.
Decode a Base64 Encoded String
echo -n "SGVsbG8gV29ybGQ=" | openssl base64 -d
Decodes the previously encoded string 'SGVsbG8gV29ybGQ=' back to its original form.
Encode a File to Base64 and Save to File
echo "This is a test file." > input.txt && openssl base64 -in input.txt -out output.b64
Encodes the file input.txt to Base64 and saves it to output.b64. (Creates input.txt for the example)
Decode a Base64 Encoded File and Save to File
openssl base64 -d -in output.b64 -out decoded.txt
Decodes the file output.b64 and saves it to decoded.txt.
Base64 Encode Without Newlines
echo -n "SingleLine" | openssl base64 -A
Outputs the Base64 encoded result on a single line without any newline characters.
Tips & Considerations
Useful tips and points to consider when using `openssl base64`.
Using Pipes (|)
You can flexibly use pipes to connect the output of other commands as input to `openssl base64`, or to pipe the output of `openssl base64` to other commands.
- Example: cat image.jpg | openssl base64 > image.b64
Security Considerations
Base64 encoding is not encryption. It is merely a conversion of binary data to a text format. Therefore, sensitive information should always be encrypted before Base64 encoding.
- Important: Base64 is encoding, not encryption.
Difference from Other `base64` Commands
GNU/Linux systems also have a separate command named `base64`. While its functionality is similar to `openssl base64`, there can be differences in some options or default behaviors. For instance, GNU `base64` typically adds newlines every 76 characters, whereas `openssl base64` does not by default (this can be controlled with the `-w` option).
- Note: GNU `base64` and `openssl base64` are distinct commands.