MD5 encryption and python implementation

MD5 file encryption python implementation

MD5 file encryption

MD5, full name Message Digest Algorithm 5, Chinese name is Message Digest Algorithm, which is a hash function widely used in the field of computer security to provide integrity protection of messages. It mainly converts text information into a short information digest through a specific hash method, and the combination of compression + encryption + hash algorithm is irreversible.
main application


1. The typical application of MD5 for consistency verification isThe MD5 code of different messages (files) is different, so it is often used to check whether the file has been modified

2, digital certificate
digital signature application.

3. Secure access authentication
In the Unix system, the user's password is stored in the file system by MD5 (or other similar algorithms) after Hash operation. When the user logs in, the system performs the MD5 Hash operation on the password entered by the user, and then compares it with the MD5 value stored in the file system to determine whether the entered password is correct. Through such steps, the system can determine the legitimacy of the user's login to the system without knowing the clear code of the user's password.

MD5 processes the input information in 512-bit groups, and each group is divided into 16 32-bit subgroups. After a series of processing, the output of the algorithm consists of four 32-bit groups. A 128-bit hash value is generated after the packets are concatenated.

python implementation

#!/usr/bin/python
import io
import hashlib

def main(name):
    m = hashlib.md5()
    file = io.FileIO(name,'r')
    bytes = file.read(10240)
    while(bytes != b''):
      m.update(bytes)
      bytes = file.read(10240)
    file.close()
    md5value = m.hexdigest()
    print(md5value)

if __name__ == '__main__':
    main('F:\System\WIN GHO\win7.GHO')

EXE generation software

https://download.csdn.net/download/weixin_41744192/20082828
insert image description here

Guess you like

Origin blog.csdn.net/weixin_41744192/article/details/118570486