1. 程式人生 > >python實現MD5加密

python實現MD5加密

# -*- coding: utf-8 -*-
import hashlib


def md5value(s):
    md5 = hashlib.md5()
    md5.update(s)
    return md5.hexdigest()
#對字典中的值進行加密
def mdfive():
    sign = {'phone':'18503008588','workAddress':'深圳市南山區科技中一路19號賽百諾大廈'}
    for k, v in sign.items():
        print(v, '->', md5value(v.encode()))

if
__name__ == '__main__': mdfive()

結果顯示:
這裡寫圖片描述

# -*- coding: utf-8 -*-
import hashlib


def md5value(s):
    md5 = hashlib.md5()
    md5.update(s)
    return md5.hexdigest()
#對單個值進行加密
def mdfive2():
    sign = "123"
    print(md5value(sign))

if __name__ == '__main__':
    mdfive2()