-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython hashing and security.py
131 lines (48 loc) · 1.33 KB
/
python hashing and security.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import hashlib
# In[2]:
dir(hashlib)
# In[3]:
text = "Hello, How are you ?"
# # Hashing String Using MD5
# In[4]:
md5_hash_obj = hashlib.md5(text.encode())
# In[5]:
print( f"The byte equivalent of MD5 hash is: \n{md5_hash_obj.digest()}")
# # Hashing String Using SHA1
# In[6]:
sha1_hash_obj = hashlib.sha1(text.encode())
# In[7]:
print( f"The byte equivalent of SHA1 hash is: \n{sha1_hash_obj.digest()}")
# # Hashing String Using SHA224
# In[8]:
sha224_hash_obj = hashlib.sha224(text.encode())
# In[9]:
print( f"The byte equivalent of SHA224 hash is: \n{sha224_hash_obj.digest()}")
# # Hashing String Using SHA256
# In[10]:
sha256_hash_obj = hashlib.sha256(text.encode())
# In[11]:
print( f"The byte equivalent of SHA256 hash is: \n{sha256_hash_obj.digest()}")
# # SALTING AND ITERARTION
# In[12]:
import uuid
# In[13]:
salt = uuid.uuid4().hex
# In[14]:
hash_pwd_1_obj = hashlib.sha512((salt + text).encode())
# In[15]:
hash1 = hash_pwd_1_obj.digest()
# In[16]:
print( f"The byte equivalent of SHA512 hash is: \n{hash1}")
# In[17]:
hash_pwd = hash_pwd_1_obj
for i in range(5):
hash_pwd1 = hashlib.sha512(hash_pwd.digest())
hash_pwd = hash_pwd1
print(f"Hash {i} --> {hash_pwd.digest()} \n")
# In[18]:
print("Done")
# In[ ]: