[Python] Shell MD5 usage

Source: Internet
Author: User
Tags openssl md5

[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 lessonUsage

List the methods used as much as possible. Multiple methods can be used to verify each other.

String MD5Shell Mode

Generallymd5sumCommand (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,LuaJITWe 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

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.