Base64 encoding is very common in e-mails. For emails such as Foxmail and outlook, the user agent performs SMTP verification when sending emails, that is, entering the username and password in base64 encoding format for verification, the body content and attachments of emails are generally transmitted using base64 encoding.
When using the Telnet tool to test mail sending, if verification is required, the practical base64 encoding tool becomes necessary. In another articleArticlePHP functions can be used for implementation. Here we will introduce a more practical Linux tool: base64
The base64 tool of rhel5 is in the coreutils installation package. It is usually installed in Linux. The following example describes how to use base64 and related precautions.
This is the file in the test file. The content has only one line of string "snailwarrior ".
[Root @ PPS ~] # Cat File
1. encode the file in base64 format and print it to the standard output.
[Root @ PPS ~] # Base64 File
You can also do this:
[Root @ PPS ~] # Cat file | base64
2. Read the file content from the standard input, encoded in base64, and printed to the standard output.
[Root @ PPS ~] # Base64
I entered the "snilwarrior", Press enter, and press Ctrl + D to end the file.
[Note] If I do not press enter, enter Ctrl + d twice in a row to see how it works:
[Root @ PPS ~] # Base64
The encoded string is c25hawx3yxjyaw9y.
My God! The results of the two encoding methods are different! Continue the test.
3. encode the string "snilwarrior" and print it to the standard output.
[Root @ PPS ~] # Echo "snailwarrior" | base64
This result is the same as the previous "cat file" and the entered "snailwarrior" Press ENTER "and press Ctrl + D. Why is the result of pressing CTRL + d twice without pressing enter different? Let's take a look at the following example:
[Root @ PPS ~] # Echo-n "snilwarrior" | base64
Are you surprised to find out why?
The echo-N option does not output the ''line break character at the end of the string. Therefore, the exact base64 encoding of the string" snailwarrior "is" c25hawx3yxjyaw9y ", which can be verified by the PHP function. The file encoding method and other "snilwarrior" strings are all encoded with ''. Therefore, an inexplicable Encoding Error occurs if you are not careful.
4. base64 Decoding
[Root @ PPS ~] # Echo-n "c25hawx3yxjyaw9y" | base64-d
[Root @ PPS ~] #
From: http://www.soft6.com/tech/13/134492.html and make appropriate adjustments