Python - hashlib (encryption module)

Mainly used for encryption of the character string, is the most commonly used encryption MD5:

hashlib Import 

DEF get_md5 (Data): 
    obj = hashlib.md5 () 
    obj.update (data.encode ( 'UTF-. 8')) 
    Result = obj.hexdigest () 
    return Result 
Val = get_md5 ( '123') put here # to encrypt the string literal. 
print (val)

If you want to avoid the hit library behavior, you can change the value to salt the encryption more complex, so it is more difficult to decipher. 

hashlib Import 

DEF get_md5 (Data): 
    obj = hashlib.md5 ( 'abclasjd; flasdkfhowheofwa123113'.encode (' UTF-. 8 ')) # where salt 
    obj.update (data.encode (' UTF-. 8 ')) 
    Result = obj.hexdigest () 
    return Result 
Val = get_md5 ( '123') to be placed here # encrypted string literal. 
print (val)

 

Case:

Description: The user enters the new user name and password into the dictionary list to form MD5 encrypted form. Let the user enter a user name and password to match.

 

Guess you like

Origin www.cnblogs.com/xinbing/p/12053844.html
Recommended