Analysis of Common Python encryption module usage [MD5, sha, crypt module], pythoncrypt

Source: Internet
Author: User
Tags crypt

Analysis of Common Python encryption module usage [MD5, sha, crypt module], pythoncrypt

This example describes the usage of common Python encryption modules. We will share this with you for your reference. The details are as follows:

1. md5 Module

md5.new([arg])Returns an md5 object. If a parameter is provided, it is equivalent to calling update (arg)
md5.update(arg)Use the string parameter arg to update the md5 object
md5.digest()Returns a 16-byte digest, which is generated by a string sent to update. The Digest does not contain ascii characters.
md5.hexdigest()Returns the abstract in hexadecimal format.

import md5a = md5.new('passwd')a.digest()  'v\xa2\x17;\xe692T\xe7/\xfaMm\xf1\x03\n'a.hexdigest()  '76a2173be6393254e72ffa4d6df1030a'a.update('hello world')a.digest()  '\xb2\x83f\xb8\x14\xc9\xc6\x19k\x01\xfe\xd8\xd9\x8f\xe0H'a.hexdigest()  'b28366b814c9c6196b01fed8d98fe048'

2. sha Module

Same as md5

import shab=sha.new('passwd')b.digest() "0'LG\x90;\xd1\xba\xc7c;\xbf\tt1I\xeb\xab\x80_"b.hexdigest() '30274c47903bd1bac7633bbf09743149ebab805f'b.update('hello')b.digest() 'c\xc19\xb4]YGz\x85\xe8C\x8fF\xfe\x9e\xc3|\xb16\xba'b.hexdigest() '63c139b45d59477a85e8438f46fe9ec37cb136ba

3. crypt

In the crypt module, there is a function, crypt (str, salt) --> string

from crypt import cryptcrypt('passwd','a') 'aaIslqfNH03LA'crypt('passwd','abc') 'ab8RogIKnX0og'crypt('passwd','a') 'aaIslqfNH03LA'

PS: if you are interested in encryption and decryption, refer to the online tools on this site:

Online text encryption and decryption tools (including AES, DES, and RC4 ):
Http://tools.jb51.net/password/txt_encode

MD5 online encryption tool:
Http://tools.jb51.net/password/CreateMD5Password

Online hash/hash algorithm encryption tool:
Http://tools.jb51.net/password/hash_encrypt

Online MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160 encryption tools:
Http://tools.jb51.net/password/hash_md5_sha

Online sha1/shaloud/sha256/sha384/sha512 encryption tool:
Http://tools.jb51.net/password/sha_encode

Related Article

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.