FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-2/pswEncrypt.py at master · ossoen/python-2 · GitHub
ossoen
/
python-2
Public
forked from
zhanghe06/python
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-2
/
pswEncrypt.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (43 loc) · 1.46 KB
Breadcrumbs
python-2
/
pswEncrypt.py
Copy path
File metadata and controls
58 lines (43 loc) · 1.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# encoding: utf-8
__author__
=
'zhanghe'
import
hashlib
class
EncryptPsw
():
def
__init__
(
self
):
pass
def
_user_to_bin
(
self
,
user
):
return
self
.
_hex_to_bin
(
hex
(
int
(
user
))[
2
:].
zfill
(
16
))
def
encrypt
(
self
,
user
,
psw
,
verify_code
):
bin_user
=
self
.
_user_to_bin
(
user
)
psw_1
=
self
.
_md5_encrypt_1
(
psw
)
psw_1
=
self
.
_hex_to_bin
(
psw_1
)
psw_2
=
self
.
_md5_encrypt_2
(
psw_1
,
bin_user
)
psw_3
=
self
.
_md5_encrypt_3
(
psw_2
,
verify_code
)
return
psw_3
@
staticmethod
def
_hex_to_bin
(
string
):
# 字符串转bytes数组
length
=
len
(
string
)
tmp
=
[]
for
i
in
range
(
0
,
length
,
2
):
tmp
.
append
(
int
(
"0x"
+
string
[
i
:
i
+
2
],
base
=
16
))
return
bytes
(
tmp
)
@
staticmethod
def
_md5_encrypt_1
(
psw
):
# 密码的第一次加密
md5
=
hashlib
.
md5
()
md5
.
update
(
psw
.
encode
(
"ISO-8859-1"
))
return
md5
.
hexdigest
().
upper
()
@
staticmethod
def
_md5_encrypt_2
(
psw
,
user
):
# 密码的第二次加密
md5
=
hashlib
.
md5
()
md5
.
update
(
psw
+
user
)
return
md5
.
hexdigest
().
upper
()
@
staticmethod
def
_md5_encrypt_3
(
psw
,
verify_code
):
# 密码的第三次加密
md5
=
hashlib
.
md5
()
md5
.
update
((
psw
+
verify_code
.
upper
()).
encode
(
"ISO-8859-1"
))
return
md5
.
hexdigest
().
upper
()
def
main
():
a
=
EncryptPsw
()
psw
=
a
.
encrypt
(
"888888888"
,
"123456"
,
"!xyz"
)
print
(
psw
)
if
__name__
==
"__main__"
:
main
()
Back
|
FazBrowse Home
|
New Git URL