Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
ops_sdk
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PublicSource
ops_sdk
Commits
410d7db9
Commit
410d7db9
authored
May 06, 2019
by
shenshuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增加密模块
parent
05e0664f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
3 deletions
+54
-3
__init__.py
opssdk/operate/__init__.py
+51
-0
setup.py
setup.py
+3
-3
No files found.
opssdk/operate/__init__.py
View file @
410d7db9
...
...
@@ -11,6 +11,7 @@ import sys
import
time
import
re
import
subprocess
import
base64
from
Crypto.Cipher
import
AES
from
binascii
import
b2a_hex
,
a2b_hex
...
...
@@ -97,6 +98,56 @@ class MyCrypt:
plain_text
=
cryptor
.
decrypt
(
a2b_hex
(
text
))
.
decode
(
'utf-8'
)
return
plain_text
.
rstrip
(
'
\0
'
)
class
MyCryptV2
:
def
__init__
(
self
,
key
=
'HOrUmuJ4bCVG6EYu2docoRNNYSdDpJJw'
):
"""
Usage:
#实例化
mc = MyCrypt()
#加密方法
mc.my_encrypt('password')
#解密方法
mc.my_decrypt('ZpZjEcsqnySTz6UsXD/+TA==')
:param key:
"""
self
.
key
=
key
# str不是16的倍数那就补足为16的倍数
def
add_to_16
(
self
,
value
):
while
len
(
value
)
%
16
!=
0
:
value
+=
'
\0
'
return
str
.
encode
(
value
)
# 返回bytes
def
my_encrypt
(
self
,
text
):
"""
加密方法
:param text: 密码
:return:
"""
aes
=
AES
.
new
(
self
.
add_to_16
(
self
.
key
),
AES
.
MODE_ECB
)
# 先进行aes加密
encrypt_aes
=
aes
.
encrypt
(
self
.
add_to_16
(
text
))
# 用base64转成字符串形式
encrypted_text
=
str
(
base64
.
encodebytes
(
encrypt_aes
),
encoding
=
'utf-8'
)
.
replace
(
'
\n
'
,
''
)
# 执行加密并转码返回bytes
# print('[INFO]: 你的加密为:{}'.format(encrypted_text))
return
encrypted_text
def
my_decrypt
(
self
,
text
):
"""
解密方法
:param text: 加密后的密文
:return:
"""
# 初始化加密器
aes
=
AES
.
new
(
self
.
add_to_16
(
self
.
key
),
AES
.
MODE_ECB
)
# 优先逆向解密base64成bytes
base64_decrypted
=
base64
.
decodebytes
(
text
.
encode
(
encoding
=
'utf-8'
))
# 执行解密密并转码返回str
decrypted_text
=
str
(
aes
.
decrypt
(
base64_decrypted
),
encoding
=
'utf-8'
)
.
replace
(
'
\0
'
,
''
)
# print('[INFO]: 你的解密为:{}'.format(decrypted_text))
return
decrypted_text
### 当前时间
def
now_time
():
return
time
.
strftime
(
'
%
Y-
%
m-
%
d-
%
H-
%
M-
%
S'
,
time
.
localtime
(
time
.
time
()))
...
...
setup.py
View file @
410d7db9
...
...
@@ -9,14 +9,14 @@ from distutils.core import setup
setup
(
name
=
'opssdk'
,
version
=
'0.0.1
2
'
,
version
=
'0.0.1
3
'
,
packages
=
[
'opssdk'
,
'opssdk.logs'
,
'opssdk.operate'
,
'opssdk.install'
,
'opssdk.get_info'
,
'opssdk.utils'
,
'websdk'
],
url
=
'https://github.com/ss1917/ops_sdk/'
,
license
=
''
,
install_requires
=
[
'fire'
,
'shortuuid'
,
'pymysql===0.9.3'
,
'sqlalchemy===1.3.0'
,
'python3-pika===0.9.14'
,
'PyJWT'
,
'Crypto===1.4.1'
,
'requests'
,
'redis===2.10.6'
,
'tornado===5.0'
,
'aliyun-python-sdk-core-v3===2.8.6'
,
'aliyun-python-sdk-dysmsapi'
,
'python-dateutil===2.7.5'
,
'ldap3===2.6'
],
'aliyun-python-sdk-core-v3===2.8.6'
,
'aliyun-python-sdk-dysmsapi'
,
'python-dateutil===2.7.5'
,
'ldap3===2.6'
,
'pycryptodome'
],
author
=
'shenshuo'
,
author_email
=
'191715030@qq.com'
,
description
=
'SDK of the operation and maintenance script'
...
...
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