[Python] Shell MD5 usage
MD5 should use a lot of algorithms. Let's talk about it with your own experience.
Scenario
There are still many articles on the algorithm layer on Wikipedia.
Mainly used scenarios
Password Storage is basically useless now. After all, it is easy to use a lot of API verification to crack, and now there are quite a lot of uses. Both sides of the API have a private key, put the data and key together to generate the token, and verify the two sides (note that for unicode encoding, encode is required). This is quite a bit used, don't always forget this step,
Installing a backdoor in Xcode is a lesson
Usage
List the methods used as much as possible. Multiple methods can be used to verify each other.
String MD5Shell Mode
Generallymd5sum
Command (Centos)
# echo -n "sweet girl"|md5sum74417797d6a7200192978659effa5e2d -
Or use the openssl command
# echo -n "sweet girl"|openssl md5(stdin)= 74417797d6a7200192978659effa5e2d
Python
The code is short. The command is written here.
# python -c "import hashlib; print hashlib.md5('sweet girl').hexdigest()"74417797d6a7200192978659effa5e2d
Lua
There is no standard implementation in Lua, but C expansion and pure Lua versions are also easy to find,LuaJIT
We recommend that you use the lua-resty-string module of chunge. Based on FFI
File MD5
File verification uses the verification of file downloads.
Shell Mode
# md5sum printf.lua629fc9a9c1b1debd24e162d817f4e4a7 printf.lua
Openssl
# openssl md5 printf.luaMD5(printf.lua)= 629fc9a9c1b1debd24e162d817f4e4a7
Python
One read is required.
#coding:utf-8#@orangleliu#fname: md5file.pyimport hashlibdef md5_for_file(path, block_size=256*128, hr=True): md5 = hashlib.md5() with open(path,'rb') as f: for chunk in iter(lambda: f.read(block_size), b''): md5.update(chunk) if hr: return md5.hexdigest() return md5.digest()if __name__ == "__main__": print md5_for_file("printf.lua")
Use
# python md5file.py printf.lua629fc9a9c1b1debd24e162d817f4e4a7