Python-crypto module

The hashlib module is introduced here.

1、

2. Encryption

There are many encryption methods in the hashlib module, such as hashlib.sha224(), hashlib.blake2b(), etc. Here we take md5 encryption as an example.

When encrypting, the string cannot be encrypted directly, you need to convert the string to bytes first, and use str.encode().

Below is a complete encryption process.

Write the above functions as the following functions to implement md5 encryption of strings.

def my_md5(str):
    import hashlib
    new_str = str.encode() #Convert the string to bytes type 
    m = hashlib.md5() #Instantiate   the md5 object 
    m.update(new_str) #Encrypt   return m.hexdigest (
     ) #Get   the result and return

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325292836&siteId=291194637