Article Directory
foreword
In daily development, Base64 encryption or decryption is often performed on some important data. Base64 encryption for strings is generally implemented in the program, but on the Linux system, you can directly encrypt or decrypt strings through the base64 command.
1. Linux encrypts strings with base64
When converting a string to Base64, you can use the following command:
command: echo string | base64
For example, if you need to encrypt the string abc into base64 encoding, then enter the command on linux: echo 'abc' | base64 .
However, please note that using the echo string|base64 command will automatically add a newline character after the generated base64 encoding. If you want not to add a newline character when encrypting to base64, you can use the following command:
command: echo -n string| base64
2. Linux base64 encodes the file and prints it
If you want to base64 encode the contents of a file, you can use the following command:
Command: base64 file name
For example, to base64 encode the a.txt file, the command is:
base64 a.txt
3. Linux decoding
If you want to decode a base64 string, you can use the following command:
Command: echo string|base64 -d
For example, decode the base64 encoding of abc above, and know that the base64 encoding of abc is YWJj , then try to decode the input command
echo YWJj | base64 -d