Python's Hashlib module

Source: Internet
Author: User
Tags sha1

#-*-coding:utf-8-*-"""Python's MD5 SHA1 module"""ImportHashlib#Examples of MD5m =hashlib.md5 () m.update (b"Hello 123") M.update (b"Hello 456")Print(M.digest ())#byte stringPrint(M.hexdigest ())#stringPrint(m.digest_size)# -Print(m.block_size)# -#can also be processed at oncePrint(HASHLIB.MD5 (b"Hello 123 Hello 456"). Hexdigest ())"""module function hashlib.new (Name[,data]) name: The name of the algorithm: Byte data hashlib.algorithms_guaranteed All platforms supported by the algorithm {' SHA1 ', ' sha256 ', ' sha384 ', ' MD5 ', ' sha512 ', ' sha224 '}hashlib.algorithms_available returns the available algorithm for Python, which can be used for new (), and guaranteed is a subset of it {' RIPEMD160 '  , ' SHA1 ', ' sha256 ', ' SHA256 ', ' sha ', ' dsaencryption ', ' MD5 ', ' SHA224 ', ' SHA384 ', ' Dsa-sha ', ' Dsawithsha ', ' sha224 ', ' MD4 ', ' MD4 ', ' whirlpool ', ' SHA ', ' sha384 ', ' ripemd160 ', ' MD5 ', ' SHA1 ', ' sha512 ', ' DSA ', ' SHA512 ', ' Ecdsa-with-sha1 '}hash object Properties ha Sh.digest_size the size of the result hash.block_size block size Hash.name name Hash.update (ARG) See Example Hash.digest () byte string hash.hexdigest () String Hash.copy () returns a copy of the hash object for password encryption Hashlib.pbkdf2_hmac (hash_name, password, salt, iterations, Dklen=none) hash_name Algorithm name password The password salt to encrypt is recommended for 16 bytes or longer iterations iterations, depending on the algorithm and computational power, the Dklen result length return value is a byte string"""#Test Iteration Time#100000 0.0625 Second results#1000000 0.63 A little card, please .#10000000 6.2 unacceptable#...#10000000000 Maximum value exceededImportBinascii fromDatetimeImportDatetimet1=DateTime.Now () DK= Hashlib.pbkdf2_hmac ('MD5'B'Password'B'Salt', 100000) T2=DateTime.Now () T= (t2-t1). Seconds + (T2-T1). microseconds/1000000Print(t) m=binascii.hexlify (DK)Print(m)

Python's Hashlib module

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.