Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
InterfaceAutoTest
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TestAuto
InterfaceAutoTest
Commits
9ffa4443
Commit
9ffa4443
authored
Apr 30, 2021
by
taoke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加加密类
parent
5bb0a00e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
9 deletions
+27
-9
common/utils.py
+27
-9
No files found.
common/utils.py
View file @
9ffa4443
import
requests
import
requests
,
hashlib
import
json
from
config
import
BaseConfig
class
RedisBase
:
pas
s
from
Crypto.Cipher
import
AES
from
Crypto.Util.Padding
import
pad
from
base64
import
encodebyte
s
def
dingTalk
(
webhook
,
message
):
"""发送消息到钉钉群"""
...
...
@@ -12,7 +12,26 @@ def dingTalk(webhook, message):
post_data
=
json
.
dumps
(
data
)
response
=
requests
.
post
(
webhook
,
headers
=
BaseConfig
.
headers
,
data
=
post_data
)
return
response
.
text
qwew
qwe
qwe
we
\ No newline at end of file
# 加密类
class
Encryption
:
def
get_md5
(
self
,
pwd
):
"""md5加密成32位小写"""
md5
=
hashlib
.
md5
()
if
pwd
:
md5
.
update
(
pwd
.
encode
(
'utf-8'
))
return
md5
.
hexdigest
()
.
lower
()
else
:
return
''
def
aes_cipher
(
self
,
key
,
aes_str
):
"""AES采用ECB模式,使用PKCS7补偿"""
aes
=
AES
.
new
(
key
.
encode
(
'utf-8'
),
AES
.
MODE_ECB
)
pad_pkcs7
=
pad
(
aes_str
.
encode
(
'utf-8'
),
AES
.
block_size
,
style
=
'pkcs7'
)
# 选择pkcs7补全
encrypt_aes
=
aes
.
encrypt
(
pad_pkcs7
)
# 加密结果
encrypted_text
=
str
(
encodebytes
(
encrypt_aes
),
encoding
=
'utf-8'
)
# 解码
encrypted_text_str
=
encrypted_text
.
replace
(
"
\n
"
,
""
)
# 此处我的输出结果老有换行符,所以用了临时方法将它剔除
return
encrypted_text_str
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment