Using MD5 encryption BASE64 encryption under Linux

Source: Internet
Author: User
Tags base64 encode decrypt md5 encryption openssl aes openssl md5 openssl sha1 sha1

Here is a string 123456 for example, its MD5 ciphertext value is: e10adc3949ba59abbe56e057f20f883e
Here, 1.txt is the file that needs to be encrypted.

First, the method of encrypting strings and files with Oppnssl MD5.
1. Oppnssl MD5 method of encrypting strings
A. Manually enter commands and procedures as follows:
#openssl//Enter OpenSSL in the terminal and return.
openssl> MD5//input MD5 rear return
123456//Then enter 123456, do not enter the carriage return. Then press 3 times to ctrl+d.
123456E10ADC3949BA59ABBE56E057F20F883E//123456 is behind the ciphertext.
Explanation: Why not enter after entering 123456?
is because OpenSSL defaults to a carriage return as a character in the string to be encrypted, so the results are different. If you enter 123456 then enter, press 2 times ctrl+d. The resulting results are:
Openssl> MD5
123456
F447B20A7FCBF53A5D5BE013EA0B15AF//Because OpenSSL does not ignore carriage return caused by
B. or directly with the pipe command
# echo-n 123456 | OpenSSL MD5//must have the-n parameter, otherwise it is not the result.
e10adc3949ba59abbe56e057f20f883e
Explanation: Why add-N to this parameter?
-N means not entering a carriage return so that the correct result can be obtained. If you do not add-N, then the result is the same as before:
F447B20A7FCBF53A5D5BE013EA0B15AF//Because OpenSSL does not ignore carriage return caused by
2. Encrypt files with OpenSSL.
#openssl MD 5-in 1.txt
  
################################################# #3
OpenSSL other related cryptographic command parameters: Citation: Utility command: BASE64 codec with OpenSSL, MD5/SHA1 Digest, AES/DES3 encryption and decryption collection
I. BASE64 encoding and decoding using the OpenSSL command (base64 Encode/decode)
1. BASE64 Encoding Command
Base64 encoding of the string ' abc ':
# echo ABC | OpenSSL base64
ywjjcg== (coded result)
If a file is Base64 encoded (file name T.txt):
# OpenSSL base64-in T.txt
2. BASE64 decoding command
Find the original text of the string ' ywjjcg== ' after base64:
# echo ywjjcg== | OpenSSL base64-d
ABC (decoding result)
If a file is Base64 decoded (file name T.base64):
# OpenSSL base64-d-in t.base64
Two. MD5/SHA1 summary using the OpenSSL command (Digest)
1. MD5 summary calculation for string ' ABC ': ECHO ABC | OpenSSL MD5
If a file is MD5 summary calculation: OpenSSL md5-in t.txt
2. SHA1 summary calculation for string ' ABC ': ECHO ABC | OpenSSL SHA1
If a file is SHA1 summary calculation: OpenSSL sha1-in t.txt
Three. Aes/des3 encryption and decryption using the OpenSSL command (Aes/des3 encrypt/decrypt)
AES encryption of the string ' abc ', using key 123, the output results are given in Base64 encoding format:
# echo ABC | OpenSSL aes-128-cbc-k 123-base64
u2fsdgvkx18ynibzarm15ng/ja2dhn4mtiotwd7jt4g= (Result)
The above results are decrypted:
# echo u2fsdgvkx18ynibzarm15ng/ja2dhn4mtiotwd7jt4g= | OpenSSL aes-128-cbc-d-K 123-base64
ABC (Result)
To encrypt (decrypt) the original text (ciphertext) from the file, just specify the-in parameter to point to the file name.
Des3 and decryption, as long as the command in the AES-128-CBC replaced Des3 on it.
Note: You can see more security algorithms with the help of OpenSSL.
###############################################
  
Second, using PHP's MD5 function to encrypt the string
#touch a.php//Create a.php file
#vi a.php//edit a.php file with VI
<?php Echo MD5 (123456),?> input and save
#php a.php//Run a.php file
Display: e10adc3949ba59abbe56e057f20f883e
Iii. use of the md5sum command
A. On Linux or UNIX, md5sum is the tool that is used to calculate and verify the file digest. In general, after installing Linux, there will be md5sum this tool, directly run directly at the command line terminal. You can use the following command to get the md5sum command to help man md5sum
#md5sum Help
There is a hint: "With no file, or when file was-, read standard input." "If the input file option is not available or the file option is--read the input from the tile", which can be encrypted by reading the string directly from the keyboard.
Ways to encrypt strings using md5sum
# md5sum//Then ENTER
123456//Enter 123456. Then press two times ctrl+d.
Show:
123456E10ADC3949BA59ABBE56E057F20F883E Red represents the value after encryption
You can also use the pipe command:
#echo-n ' 123123 ' | Md5sum
  
or write MD5 encryption script, called Md5.sh,
Copy the following into the script:
#!/bin/bash
Echo-n $ | md5sum | awk ' {print '} '
  
After saving, execute permissions to the script.
#sh md5.sh 123456
Display: e10adc3949ba59abbe56e057f20f883e
B. You can actually put the text in a text file, and then use md5sum encryption to change the text, you can also get the value of string encryption. The process is as follows:
#touch A.txt
#echo-N 123456 > A.txt//Writes 123456 into a text file, cannot lose the –n parameter, avoids the carriage return interference
#md5sum A.txt
Display: e10adc3949ba59abbe56e057f20f883e a.txt
  
There are two meanings of ctrl+d:
One is to send the file entry terminator to the program EOF.
The second is to send exit instructions to the program. The program receives the signal after the specific action is to end the input, and then wait, or direct exit, it depends on how the program captures the signal after the operation.
Md5sum belongs to the first meaning. Two plays Strl+d, the first time the EOF instruction is read, the capture will be treated as the exit instruction. A shell-type program will parse the CTRL+D directly into an exit instruction.

Using MD5 encryption BASE64 encryption under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.