Md5 encryption method for python files,

Source: Internet
Author: User

Md5 encryption method for python files,

This document describes the md5 encryption method for python files. We will share this with you for your reference. The details are as follows:

Simple mode:

From hashlib import md5def md5_file (name): m = md5 () a_file = open (name, 'rb') # Read File Content in binary format m. update (a_file.read () a_file.close () return m. hexdigest () if _ main _ = '_ init _': print md5_file ('d:/test.txt ')

Faster speed of large files

#!/usr/bin/python#encoding=utf-8import ioimport sysimport hashlibimport stringdef printUsage():  print ('''''Usage: [python] pymd5sum.py <filename>''')def main():  if(sys.argv.__len__()==2):    #print(sys.argv[1])    m = hashlib.md5()    file = io.FileIO(sys.argv[1],'r')    bytes = file.read(1024)    while(bytes != b''):      m.update(bytes)      bytes = file.read(1024)    file.close()    #md5value = ""    md5value = m.hexdigest()    print(md5value+"\t"+sys.argv[1])    #dest = io.FileIO(sys.argv[1]+".CHECKSUM.md5",'w')    #dest.write(md5value)    #dest.close()  else:    printUsage()main()

I hope this article will help you with Python programming.

Articles you may be interested in:
  • Use md5sum in Python to check the sharing of the same file code in the directory
  • Example of using the md5, sha, and crypt encryption modules of Python
  • Example of using MD5 to encrypt a string in Python
  • Use Python and MD5 to detect website Trojans
  • Python MD5 file generation code
  • Python implements the RSA encryption (decryption) Algorithm
  • Use python to encrypt your own password
  • Python Implementation Method for RC4 file encryption
  • How to Implement file snapshot encryption and protection in python
  • Details about how to implement DES encryption and decryption in python
  • Python DES-based encryption and decryption instance
  • Example Analysis of base64 encryption and decryption methods in python

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.