哈希算法将任意长度二进制值映射为另一个唯一的二进制值,不可逆。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import hashlib
def md5_32_digest(text):
'''
md5加密,32位结果
:param text:
:return:
'''
md5 = hashlib.md5()
md5.update(text.encode(encoding='utf_8'))
return md5.hexdigest()
def md5_16_digest(text):
'''
md5加密,16位结果
:param text:
:return:
'''
return md5_32_digest(text)[8:-8]
def sha1_digest(text):
'''
sha1加密
:param text:
:return:
'''
sha1 = hashlib.sha1()
sha1.update(text.encode(encoding='utf_8'))
return sha1.hexdigest()
def sha224_digest(text):
'''
sha224加密
:param text:
:return:
'''
sha224 = hashlib.sha224()
sha224.update(text.encode(encoding='utf_8'))
return sha224.hexdigest()
def sha256_digest(text):
'''
sha256加密
:param text:
:return:
'''
sha256 = hashlib.sha256()
sha256.update(text.encode(encoding='utf_8'))
return sha256.hexdigest()
def sha384_digest(text):
'''
sha384加密
:param text:
:return:
'''
sha384 = hashlib.sha384()
sha384.update(text.encode(encoding='utf_8'))
return sha384.hexdigest()
def sha512_digest(text):
'''
sha512加密
:param text:
:return:
'''
sha512 = hashlib.sha512()
sha512.update(text.encode(encoding='utf_8'))
return sha512.hexdigest()