You recently need to use Python to get the MD5 value of a string.
Today put the code to share with you.
#!/usr/bin/env python #-*-coding:cp936-*- import hashlib def get_md5_value (SRC): myMd5 = HASHLIB.MD5 () mymd5.update (src) mymd5_digest = Mymd5.hexdigest () return mymd5_digest def get_sha1_ Value (SRC): mySha1 = HASHLIB.SHA1 () mysha1.update (src) mysha1_digest = Mysha1.hexdigest () Return mysha1_digest if __name__== ' __main__ ': src = ' aaa ' result_md5_value=get_md5_value (SRC) Result_sha1_value=get_sha1_value (SRC) print ' source string: ', src print ' MD5: ', Result_md5_value print ' SHA1: ', Result_sha1_value
Python is still very powerful, and here is a call to the built-in HASHLIB.MD5 () method.
Verify:
After writing the Python method, we also need to verify the correctness of this Python program.
You can execute the following command on Linux:
Echo-n ' aaa ' |md5sum|cut-d '-f1
The resulting value is: 47bce5c74f589f4867dbd57e9ca9f808 is the same as the Python script.