Python hashlib module (mainly record md5 encryption)

2010-10-21  来源:本站原创  分类:Python  人气:224 

provides a python module for encrypted hash: hashlib
One of the following major record md5 encryption

>>> Import hashlib
>>> M = hashlib.md5 ()
>>> M.update ("Nobody inspects")
>>> M.update ("the spammish repetition")
>>> M.digest ()
'\ Xbbd \ x9c \ x83 \ xdd \ x1e \ xa5 \ xc9 \ xd9 \ xde \ xc9 \ xa1 \ x8d \ xf0 \ xff \ xe9'
>>> M.hexdigest ()
'Bb649c83dd1ea5c9d9dec9a18df0ffe9'

A description of the code above:
1. First, from the python module directly into hashlib
2. Call hashlib in the md5 () generates a md5 hash object
3. Generate hash object, you can update method md5 encrypted string update processing
4. To call the update method on the basis of the previous update the encrypted encryption
5. Encrypted binary result
6. Hexadecimal Results

If you only need to encrypt a string, a statement can also be used by:

>>> Print hashlib.new ("md5", "Nobody inspects the spammish repetition"). Hexdigest ()
'Bb649c83dd1ea5c9d9dec9a18df0ffe9'

Part of the official documents refer to:

The following values are provided as constant attributes of the hash objects returned by the constructors:

hash.digest_size ¶
The size of the resulting hash in bytes.

hash.block_size ¶
The internal block size of the hash algorithm in bytes.

A hash object has the following methods:

hash.update (arg) ¶
Update the hash object with the string arg. Repeated calls are equivalent to a single call with the concatenation of all the arguments: m.update (a); m.update (b) is equivalent to m.update (a + b).

hash.digest () ¶
Return the digest of the strings passed to the update () method so far. This is a string of digest_size bytes which may contain non-ASCII characters, including null bytes.

hash.hexdigest () ¶
Like digest () except the digest is returned as a string of double length, containing only hexadecimal digits. This may be used to exchange the value safely in email or other non-binary environments.

hash.copy () ¶
Return a copy ("clone") of the hash object. This can be used to efficiently compute the digests of strings that share a common initial substring.

相关文章
  • Python hashlib module (mainly record md5 encryption) 2010-10-21

    provides a python module for encrypted hash: hashlib One of the following major record md5 encryption >>> Import hashlib >>> M = hashlib.md5 () >>> M.update ("Nobody inspects") >>> M.update ("the spammish

  • python os module in the Chinese language help file 2010-02-08

    python os module in the Chinese language help file Translator: butalnd translation in 2010.1.7 - 2010.1.8, personal blog: http://butlandblog.appspot.com/ Note that this module's function on unix are skipped most of the translation primarily for WINDO

  • Java and. Net of MD5 encryption and code difference 2010-04-13

    The first to write blog, write a bad place, please forgive me, decided to start writing blog mainly to record what they have learned something every day, but also hope, if possible, for beginners like me friend a little help, because I is also a begi

  • Java MD5 Encryption 2010-03-29

    public class MD5 { //MD5 Encryption. A 32-bit public static String MD5jm(String str) { MessageDigest md5 = null; try { md5 = MessageDigest.getInstance("MD5"); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); return

  • Java MD5 encryption generated summary 2010-03-29

    Recent projects just need to use something a bit encryption, java security library provides a class java.security.MessageDigest This MessageDigest class provides applications with message digest algorithm features, such as MD5 or SHA algorithm. Messa

  • MD5 encryption and Base64 Encryption and Decryption Algorithm 2008-10-05

    package com.john.j2se.util; /** * MD5 Encryption algorithm */ import java.security.MessageDigest; public class MD5Util { public final static String MD5(String s) { char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',

  • python re module sub method 2010-04-16

    python re module sub method introduced re.sub function with regular expression-based replacement work >>> import re >>> re.search('[abc]', 'Mark') <_sre.SRE_Match object at 0x001C1FA8> >>> re.sub('[abc]', 'o', 'Mark') 'Mor

  • Java MD5 encryption on the characters 2010-05-03

    What specifically is the MD5 I will not say here, to the actual point. import java.security.MessageDigest; public class MD5Util ( / ** * Convert byte array to hexadecimal string * @ Param bytes array * @ Return a hex string * / private static String

  • The md5 encryption c # 2010-05-21

    public string md5 (string str, int code) ( if (code == 16) / / 16 Bit MD5 encryption (32-bit encryption to take 9 to 25 characters) ( return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (str, "MD5"). ToLower (). Sub

  • java md5 encryption type 2010-07-28

    package com.joinintech.jaguar.function; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; / ** * MD5 encryption * * / public class MD5 ( private String [] hexDigits = ( "0", "1", "2", "3&

  • C # Class DES 3DES MD5 encryption 2010-07-29

    This is when I used to write an encrypted CMIS class. using System; using System.Security.Cryptography; using System.IO; using System.Data; using System.Web; using System.Text; using System.Security; namespace CMIS.Common { /// <summary> /// Encrypt

  • python os module API List 2010-08-06

    The standard library in Python os module contains the common operating system feature. If you want your program to work with platform-independent, then this module is particularly important. That it allows a program to be written without any changes,

  • jsp, Javascript MD5 encryption algorithm 2010-08-24

    Implement user login, registration passwords with MD5 encryption jsp receiver to achieve implementation of encryption and JavaScript are examples where the time of submission of encrypted information

  • In the history of the most simple MD5 encryption 2010-08-25

    Today was an MD5 encryption algorithm, is written in Java comes with the package. Very simple! View code public static String getMD5String(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException{ // Determine the method of calculati

  • Solve ASP.NET MD5 encryption Chinese problem of inconsistent results and ASP 2010-09-23

    When you want to be MD5 encrypted string does not contain Chinese, then the result ASP.NET and ASP of encryption is the same: <!--< Br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware) <br /> http://www.CodeHi

  • Chinese solve ASP.NET MD5 encryption problem of inconsistent results and ASP 2010-09-23

    When the string to the MD5 encryption without the Chinese, then the result ASP.NET and ASP of encryption is the same: <!--< Br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware) <br /> http://www.CodeHighlighte

  • Implemented in java php's md5 encryption 2010-09-29

    Need to build on the progress Colombia has been a problem md5 encrypted not confused a few days rest, the next thing that came in. Now, if I do not want to look after these problems occur, you can skip the final surface of the solution read: Content

  • java MD5 encryption algorithm matches the user table password field Discuz 2010-10-10

    Suddenly want to do a small test site to facilitate future development of DZ shared with users, so wrote a go with with MD5 encryption dz_uc_members DZ database table password field. Code: import java.security.MessageDigest; public class MD5ForDiscuz

  • DES encryption and decryption and MD5 encryption and decryption algorithm 2010-11-12

    DES encryption and decryption import java.security.Key; import java.security.SecureRandom; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; /** * * DES encryption and decrypti

  • java MD5 encryption algorithm 2010-11-16

    / ** * Java.security package MessageDigest class provides methods for calculating message digest, the first generation object, the implementation of its update () method of the original data can be passed to the object, and then do the digest () meth