asterisk-security 0.1.2.516.1645__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- asterisk_security-0.1.2.516.1645/LICENSE +201 -0
- asterisk_security-0.1.2.516.1645/PKG-INFO +119 -0
- asterisk_security-0.1.2.516.1645/README.md +95 -0
- asterisk_security-0.1.2.516.1645/setup.cfg +4 -0
- asterisk_security-0.1.2.516.1645/setup.py +71 -0
- asterisk_security-0.1.2.516.1645/src/asterisk_security.egg-info/PKG-INFO +119 -0
- asterisk_security-0.1.2.516.1645/src/asterisk_security.egg-info/SOURCES.txt +15 -0
- asterisk_security-0.1.2.516.1645/src/asterisk_security.egg-info/dependency_links.txt +1 -0
- asterisk_security-0.1.2.516.1645/src/asterisk_security.egg-info/entry_points.txt +3 -0
- asterisk_security-0.1.2.516.1645/src/asterisk_security.egg-info/not-zip-safe +1 -0
- asterisk_security-0.1.2.516.1645/src/asterisk_security.egg-info/requires.txt +3 -0
- asterisk_security-0.1.2.516.1645/src/asterisk_security.egg-info/top_level.txt +1 -0
- asterisk_security-0.1.2.516.1645/src/asterisksecurity/__init__.py +0 -0
- asterisk_security-0.1.2.516.1645/src/asterisksecurity/console.py +57 -0
- asterisk_security-0.1.2.516.1645/src/asterisksecurity/encryption.py +100 -0
- asterisk_security-0.1.2.516.1645/src/asterisksecurity/error.py +11 -0
- asterisk_security-0.1.2.516.1645/src/asterisksecurity/setting.json +3 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: asterisk-security
|
|
3
|
+
Version: 0.1.2.516.1645
|
|
4
|
+
Summary: Security module for asterisk series.
|
|
5
|
+
Author: Shan,Tian
|
|
6
|
+
Author-email: geoshan@163.com
|
|
7
|
+
License: Apache License 2.0
|
|
8
|
+
Keywords: encrypt,decrypt,security,asterisk
|
|
9
|
+
Platform: Independent
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Topic :: Utilities
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Requires-Python: >=3.10.0
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: colorama>=0.4.4
|
|
22
|
+
Requires-Dist: pyDes>=2.0.1
|
|
23
|
+
Requires-Dist: Deprecated>=1.2.13
|
|
24
|
+
|
|
25
|
+
# asterisk-security
|
|
26
|
+
|
|
27
|
+
## 介绍
|
|
28
|
+
|
|
29
|
+
这个小项目最初是几年前写Django的项目,想在后端写个cookie的加密功能,后来就自己动手写了一个可以加密的函数。主要是个人工作的积累而已。随着后续开发的需求,将不断将更多的个人经验总结道这个开源项目。
|
|
30
|
+
|
|
31
|
+
项目交流与缺陷提交[这里](https://gitee.com/zhangxin_1/asterisk-security)
|
|
32
|
+
|
|
33
|
+
## 软件架构
|
|
34
|
+
|
|
35
|
+
```markdown
|
|
36
|
+
/
|
|
37
|
+
|-- asterisksecurity/
|
|
38
|
+
| |-- encryption.py
|
|
39
|
+
| | |-- AsteriskEncrypt
|
|
40
|
+
| |
|
|
41
|
+
| |-- error.py
|
|
42
|
+
| | |-- InvalidEncriptionKey
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 安装教程
|
|
46
|
+
|
|
47
|
+
1. `pip install asterisk-security`
|
|
48
|
+
|
|
49
|
+
## 使用说明
|
|
50
|
+
|
|
51
|
+
### 安装后在python代码中引入,实例化后调用
|
|
52
|
+
|
|
53
|
+
1. 需要以key来实例化`AsteriskEncrypt`类
|
|
54
|
+
2. `encrypt`方法可以将传参字符串进行加密并返回字符串
|
|
55
|
+
3. `decrypt`方法将已加密的字符串进行解密
|
|
56
|
+
|
|
57
|
+
例子:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from asterisksecurity.encryption import AsteriskEncrypt
|
|
61
|
+
|
|
62
|
+
def test_encrypt():
|
|
63
|
+
key = 'X7UJi2VdqcQlc3thv2dDPEn5y3yv3eTk35yyAhlKeAY1'
|
|
64
|
+
a = AsteriskEncrypt(key)
|
|
65
|
+
s = '你好世界!Hello World!'
|
|
66
|
+
s_enc = a.encrypt(s)
|
|
67
|
+
print(s_enc)
|
|
68
|
+
|
|
69
|
+
a_dec = a.decrypt(s_enc)
|
|
70
|
+
print(a_dec)
|
|
71
|
+
|
|
72
|
+
if __name__ == '__main__':
|
|
73
|
+
test_encrypt()
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 直接使用命令行
|
|
78
|
+
|
|
79
|
+
* 使用asencrypt命令
|
|
80
|
+
|
|
81
|
+
```command-line
|
|
82
|
+
usage: asencrypt [-h] [-key K] [-txt T]
|
|
83
|
+
|
|
84
|
+
asterisk-security加密工具
|
|
85
|
+
|
|
86
|
+
options:
|
|
87
|
+
-h, --help show this help message and exit
|
|
88
|
+
-key K 加密密钥,长度不能超过22个字符,否则,进行左右11个字符截取,格式:[a-zA-Z0-9]+,不得包含特殊字符 encrypt key, length should not exceed 22 characters, otherwise, left and
|
|
89
|
+
right 11 characters will be intercepted, format: [a-zA-Z0-9]+, no special characters allowed
|
|
90
|
+
-txt T 需要加密的字符串 string to be encrypted```markdown
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
* 使用asdecrypt命令
|
|
96
|
+
|
|
97
|
+
```command-line
|
|
98
|
+
usage: asdecrypt [-h] [-key K] [-txt T]
|
|
99
|
+
|
|
100
|
+
asterisk-security解密工具
|
|
101
|
+
|
|
102
|
+
options:
|
|
103
|
+
-h, --help show this help message and exit
|
|
104
|
+
-key K 解密密钥,长度不能超过22个字符,否则,进行左右11个字符截取,格式:[a-zA-Z0-9]+,不得包含特殊字符 decrypt key, length should not exceed 22 characters, otherwise, left and
|
|
105
|
+
right 11 characters will be intercepted, format: [a-zA-Z0-9]+, no special characters allowed
|
|
106
|
+
-txt T 需要解密的字符串 string to be decrypted
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## 错误说明
|
|
110
|
+
|
|
111
|
+
1. key字符串如果不符合格式要求,会抛出error
|
|
112
|
+
2. 其他在解密过程中有任何error都不做处理。
|
|
113
|
+
|
|
114
|
+
## 参与贡献
|
|
115
|
+
|
|
116
|
+
1. Fork 本仓库
|
|
117
|
+
2. 新建 Feat_xxx 分支
|
|
118
|
+
3. 提交代码
|
|
119
|
+
4. 新建 Pull Request
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# asterisk-security
|
|
2
|
+
|
|
3
|
+
## 介绍
|
|
4
|
+
|
|
5
|
+
这个小项目最初是几年前写Django的项目,想在后端写个cookie的加密功能,后来就自己动手写了一个可以加密的函数。主要是个人工作的积累而已。随着后续开发的需求,将不断将更多的个人经验总结道这个开源项目。
|
|
6
|
+
|
|
7
|
+
项目交流与缺陷提交[这里](https://gitee.com/zhangxin_1/asterisk-security)
|
|
8
|
+
|
|
9
|
+
## 软件架构
|
|
10
|
+
|
|
11
|
+
```markdown
|
|
12
|
+
/
|
|
13
|
+
|-- asterisksecurity/
|
|
14
|
+
| |-- encryption.py
|
|
15
|
+
| | |-- AsteriskEncrypt
|
|
16
|
+
| |
|
|
17
|
+
| |-- error.py
|
|
18
|
+
| | |-- InvalidEncriptionKey
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 安装教程
|
|
22
|
+
|
|
23
|
+
1. `pip install asterisk-security`
|
|
24
|
+
|
|
25
|
+
## 使用说明
|
|
26
|
+
|
|
27
|
+
### 安装后在python代码中引入,实例化后调用
|
|
28
|
+
|
|
29
|
+
1. 需要以key来实例化`AsteriskEncrypt`类
|
|
30
|
+
2. `encrypt`方法可以将传参字符串进行加密并返回字符串
|
|
31
|
+
3. `decrypt`方法将已加密的字符串进行解密
|
|
32
|
+
|
|
33
|
+
例子:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from asterisksecurity.encryption import AsteriskEncrypt
|
|
37
|
+
|
|
38
|
+
def test_encrypt():
|
|
39
|
+
key = 'X7UJi2VdqcQlc3thv2dDPEn5y3yv3eTk35yyAhlKeAY1'
|
|
40
|
+
a = AsteriskEncrypt(key)
|
|
41
|
+
s = '你好世界!Hello World!'
|
|
42
|
+
s_enc = a.encrypt(s)
|
|
43
|
+
print(s_enc)
|
|
44
|
+
|
|
45
|
+
a_dec = a.decrypt(s_enc)
|
|
46
|
+
print(a_dec)
|
|
47
|
+
|
|
48
|
+
if __name__ == '__main__':
|
|
49
|
+
test_encrypt()
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 直接使用命令行
|
|
54
|
+
|
|
55
|
+
* 使用asencrypt命令
|
|
56
|
+
|
|
57
|
+
```command-line
|
|
58
|
+
usage: asencrypt [-h] [-key K] [-txt T]
|
|
59
|
+
|
|
60
|
+
asterisk-security加密工具
|
|
61
|
+
|
|
62
|
+
options:
|
|
63
|
+
-h, --help show this help message and exit
|
|
64
|
+
-key K 加密密钥,长度不能超过22个字符,否则,进行左右11个字符截取,格式:[a-zA-Z0-9]+,不得包含特殊字符 encrypt key, length should not exceed 22 characters, otherwise, left and
|
|
65
|
+
right 11 characters will be intercepted, format: [a-zA-Z0-9]+, no special characters allowed
|
|
66
|
+
-txt T 需要加密的字符串 string to be encrypted```markdown
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
* 使用asdecrypt命令
|
|
72
|
+
|
|
73
|
+
```command-line
|
|
74
|
+
usage: asdecrypt [-h] [-key K] [-txt T]
|
|
75
|
+
|
|
76
|
+
asterisk-security解密工具
|
|
77
|
+
|
|
78
|
+
options:
|
|
79
|
+
-h, --help show this help message and exit
|
|
80
|
+
-key K 解密密钥,长度不能超过22个字符,否则,进行左右11个字符截取,格式:[a-zA-Z0-9]+,不得包含特殊字符 decrypt key, length should not exceed 22 characters, otherwise, left and
|
|
81
|
+
right 11 characters will be intercepted, format: [a-zA-Z0-9]+, no special characters allowed
|
|
82
|
+
-txt T 需要解密的字符串 string to be decrypted
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 错误说明
|
|
86
|
+
|
|
87
|
+
1. key字符串如果不符合格式要求,会抛出error
|
|
88
|
+
2. 其他在解密过程中有任何error都不做处理。
|
|
89
|
+
|
|
90
|
+
## 参与贡献
|
|
91
|
+
|
|
92
|
+
1. Fork 本仓库
|
|
93
|
+
2. 新建 Feat_xxx 分支
|
|
94
|
+
3. 提交代码
|
|
95
|
+
4. 新建 Pull Request
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from setuptools import setup,find_packages
|
|
2
|
+
import time,json
|
|
3
|
+
|
|
4
|
+
'''
|
|
5
|
+
只提供setup.py文件,setup.cfg文件将在后续版本提供
|
|
6
|
+
使用以下命令生成whl文件:
|
|
7
|
+
python3.10 setup.py bdist_wheel
|
|
8
|
+
注意:需要提前安装wheel包
|
|
9
|
+
'''
|
|
10
|
+
|
|
11
|
+
with open('src/asterisksecurity/setting.json','r',encoding='utf8') as fp:
|
|
12
|
+
setting = json.load(fp)
|
|
13
|
+
|
|
14
|
+
build_no = time.strftime('%m%d.%H%M',time.localtime())
|
|
15
|
+
# 该版本号将在后续版本中以package的属性实现,以便于setup.cfg文件方便使用
|
|
16
|
+
|
|
17
|
+
with open('README.md','r',encoding='utf-8') as fp:
|
|
18
|
+
long_description = fp.read()
|
|
19
|
+
|
|
20
|
+
setup(
|
|
21
|
+
name="asterisk-security", #pypi中的名称,pip或者easy_install安装时使用的名称
|
|
22
|
+
version="{}.{}".format(setting['version'],build_no),
|
|
23
|
+
author="Shan,Tian",
|
|
24
|
+
author_email="geoshan@163.com",
|
|
25
|
+
description=("Security module for asterisk series."),
|
|
26
|
+
license="Apache License 2.0",
|
|
27
|
+
keywords="encrypt,decrypt,security,asterisk",
|
|
28
|
+
packages=find_packages(where="src/",exclude=['build','dist','*egg*']), # 需要打包的目录列表,排除测试项目以及build之后产生的目录
|
|
29
|
+
package_dir={'': 'src'}, # 包对应的目录,""表示src目录
|
|
30
|
+
|
|
31
|
+
# 需要安装的依赖
|
|
32
|
+
install_requires=[
|
|
33
|
+
'colorama>=0.4.4',
|
|
34
|
+
'pyDes>=2.0.1',
|
|
35
|
+
'Deprecated >=1.2.13'
|
|
36
|
+
],
|
|
37
|
+
include_package_data=True,
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
package_data={
|
|
41
|
+
# If any package contains *.json or *.attpl or *.config files, include them:
|
|
42
|
+
"": ["*.json", "*.config"]
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
# Python版本的要求
|
|
46
|
+
python_requires='>=3.10.0',
|
|
47
|
+
|
|
48
|
+
platforms='Independent',
|
|
49
|
+
|
|
50
|
+
# 添加这个选项,是为了在安装后,可以使用命令行自动生成项目文件和目录,以及目录下的默认配置文件等
|
|
51
|
+
# 注意:模块与函数之间是冒号:
|
|
52
|
+
entry_points={'console_scripts': [
|
|
53
|
+
'asencrypt = asterisksecurity.console:encrypt',
|
|
54
|
+
'asdecrypt = asterisksecurity.console:decrypt',
|
|
55
|
+
]},
|
|
56
|
+
|
|
57
|
+
long_description=long_description, # 本段代码将在编辑readme后使用
|
|
58
|
+
long_description_content_type='text/markdown',
|
|
59
|
+
classifiers=[ # 程序的所属分类列表
|
|
60
|
+
"Development Status :: 4 - Beta",
|
|
61
|
+
"Topic :: Utilities",
|
|
62
|
+
"License :: OSI Approved :: Apache Software License",
|
|
63
|
+
"Environment :: Console",
|
|
64
|
+
"Intended Audience :: Developers",
|
|
65
|
+
"Operating System :: OS Independent",
|
|
66
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
67
|
+
"Programming Language :: Python :: 3.10"
|
|
68
|
+
],
|
|
69
|
+
# 此项需要,否则卸载时报windows error
|
|
70
|
+
zip_safe=False
|
|
71
|
+
)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: asterisk-security
|
|
3
|
+
Version: 0.1.2.516.1645
|
|
4
|
+
Summary: Security module for asterisk series.
|
|
5
|
+
Author: Shan,Tian
|
|
6
|
+
Author-email: geoshan@163.com
|
|
7
|
+
License: Apache License 2.0
|
|
8
|
+
Keywords: encrypt,decrypt,security,asterisk
|
|
9
|
+
Platform: Independent
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Topic :: Utilities
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Requires-Python: >=3.10.0
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: colorama>=0.4.4
|
|
22
|
+
Requires-Dist: pyDes>=2.0.1
|
|
23
|
+
Requires-Dist: Deprecated>=1.2.13
|
|
24
|
+
|
|
25
|
+
# asterisk-security
|
|
26
|
+
|
|
27
|
+
## 介绍
|
|
28
|
+
|
|
29
|
+
这个小项目最初是几年前写Django的项目,想在后端写个cookie的加密功能,后来就自己动手写了一个可以加密的函数。主要是个人工作的积累而已。随着后续开发的需求,将不断将更多的个人经验总结道这个开源项目。
|
|
30
|
+
|
|
31
|
+
项目交流与缺陷提交[这里](https://gitee.com/zhangxin_1/asterisk-security)
|
|
32
|
+
|
|
33
|
+
## 软件架构
|
|
34
|
+
|
|
35
|
+
```markdown
|
|
36
|
+
/
|
|
37
|
+
|-- asterisksecurity/
|
|
38
|
+
| |-- encryption.py
|
|
39
|
+
| | |-- AsteriskEncrypt
|
|
40
|
+
| |
|
|
41
|
+
| |-- error.py
|
|
42
|
+
| | |-- InvalidEncriptionKey
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 安装教程
|
|
46
|
+
|
|
47
|
+
1. `pip install asterisk-security`
|
|
48
|
+
|
|
49
|
+
## 使用说明
|
|
50
|
+
|
|
51
|
+
### 安装后在python代码中引入,实例化后调用
|
|
52
|
+
|
|
53
|
+
1. 需要以key来实例化`AsteriskEncrypt`类
|
|
54
|
+
2. `encrypt`方法可以将传参字符串进行加密并返回字符串
|
|
55
|
+
3. `decrypt`方法将已加密的字符串进行解密
|
|
56
|
+
|
|
57
|
+
例子:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from asterisksecurity.encryption import AsteriskEncrypt
|
|
61
|
+
|
|
62
|
+
def test_encrypt():
|
|
63
|
+
key = 'X7UJi2VdqcQlc3thv2dDPEn5y3yv3eTk35yyAhlKeAY1'
|
|
64
|
+
a = AsteriskEncrypt(key)
|
|
65
|
+
s = '你好世界!Hello World!'
|
|
66
|
+
s_enc = a.encrypt(s)
|
|
67
|
+
print(s_enc)
|
|
68
|
+
|
|
69
|
+
a_dec = a.decrypt(s_enc)
|
|
70
|
+
print(a_dec)
|
|
71
|
+
|
|
72
|
+
if __name__ == '__main__':
|
|
73
|
+
test_encrypt()
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 直接使用命令行
|
|
78
|
+
|
|
79
|
+
* 使用asencrypt命令
|
|
80
|
+
|
|
81
|
+
```command-line
|
|
82
|
+
usage: asencrypt [-h] [-key K] [-txt T]
|
|
83
|
+
|
|
84
|
+
asterisk-security加密工具
|
|
85
|
+
|
|
86
|
+
options:
|
|
87
|
+
-h, --help show this help message and exit
|
|
88
|
+
-key K 加密密钥,长度不能超过22个字符,否则,进行左右11个字符截取,格式:[a-zA-Z0-9]+,不得包含特殊字符 encrypt key, length should not exceed 22 characters, otherwise, left and
|
|
89
|
+
right 11 characters will be intercepted, format: [a-zA-Z0-9]+, no special characters allowed
|
|
90
|
+
-txt T 需要加密的字符串 string to be encrypted```markdown
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
* 使用asdecrypt命令
|
|
96
|
+
|
|
97
|
+
```command-line
|
|
98
|
+
usage: asdecrypt [-h] [-key K] [-txt T]
|
|
99
|
+
|
|
100
|
+
asterisk-security解密工具
|
|
101
|
+
|
|
102
|
+
options:
|
|
103
|
+
-h, --help show this help message and exit
|
|
104
|
+
-key K 解密密钥,长度不能超过22个字符,否则,进行左右11个字符截取,格式:[a-zA-Z0-9]+,不得包含特殊字符 decrypt key, length should not exceed 22 characters, otherwise, left and
|
|
105
|
+
right 11 characters will be intercepted, format: [a-zA-Z0-9]+, no special characters allowed
|
|
106
|
+
-txt T 需要解密的字符串 string to be decrypted
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## 错误说明
|
|
110
|
+
|
|
111
|
+
1. key字符串如果不符合格式要求,会抛出error
|
|
112
|
+
2. 其他在解密过程中有任何error都不做处理。
|
|
113
|
+
|
|
114
|
+
## 参与贡献
|
|
115
|
+
|
|
116
|
+
1. Fork 本仓库
|
|
117
|
+
2. 新建 Feat_xxx 分支
|
|
118
|
+
3. 提交代码
|
|
119
|
+
4. 新建 Pull Request
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
src/asterisk_security.egg-info/PKG-INFO
|
|
5
|
+
src/asterisk_security.egg-info/SOURCES.txt
|
|
6
|
+
src/asterisk_security.egg-info/dependency_links.txt
|
|
7
|
+
src/asterisk_security.egg-info/entry_points.txt
|
|
8
|
+
src/asterisk_security.egg-info/not-zip-safe
|
|
9
|
+
src/asterisk_security.egg-info/requires.txt
|
|
10
|
+
src/asterisk_security.egg-info/top_level.txt
|
|
11
|
+
src/asterisksecurity/__init__.py
|
|
12
|
+
src/asterisksecurity/console.py
|
|
13
|
+
src/asterisksecurity/encryption.py
|
|
14
|
+
src/asterisksecurity/error.py
|
|
15
|
+
src/asterisksecurity/setting.json
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
asterisksecurity
|
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from colorama import init
|
|
3
|
+
|
|
4
|
+
# 解决Window环境中打印颜色问题
|
|
5
|
+
init(autoreset=True)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def encrypt()->None:
|
|
9
|
+
'''
|
|
10
|
+
加密工具的命令行入口
|
|
11
|
+
Command line entry for encryption tools
|
|
12
|
+
'''
|
|
13
|
+
|
|
14
|
+
parser = argparse.ArgumentParser(description='asterisk-security加密工具')
|
|
15
|
+
parser.add_argument('-key', metavar='K', type=str, \
|
|
16
|
+
help='加密密钥,长度不能超过22个字符,否则,进行左右11个字符截取,格式:[a-zA-Z0-9]+,不得包含特殊字符 encrypt key, length should not exceed 22 characters, otherwise, left and right 11 characters will be intercepted, format: [a-zA-Z0-9]+, no special characters allowed')
|
|
17
|
+
parser.add_argument('-txt', metavar='T', type=str, \
|
|
18
|
+
help='需要加密的字符串 string to be encrypted')
|
|
19
|
+
|
|
20
|
+
key = parser.parse_args().key if parser.parse_args() else ''
|
|
21
|
+
txt = parser.parse_args().txt if parser.parse_args() else ''
|
|
22
|
+
if not key:
|
|
23
|
+
print('\033[31m加密密钥不能为空。\033[0m')
|
|
24
|
+
return
|
|
25
|
+
if not txt:
|
|
26
|
+
print('\033[31m需要加密的字符串不能为空。\033[0m')
|
|
27
|
+
return
|
|
28
|
+
from asterisksecurity.encryption import AsteriskEncrypt
|
|
29
|
+
a = AsteriskEncrypt(key)
|
|
30
|
+
print(f'加密结果:{a.encrypt(txt)}')
|
|
31
|
+
|
|
32
|
+
def decrypt()->None:
|
|
33
|
+
'''
|
|
34
|
+
解密工具的命令行入口
|
|
35
|
+
Command line entry for decryption tools
|
|
36
|
+
'''
|
|
37
|
+
|
|
38
|
+
parser = argparse.ArgumentParser(description='asterisk-security解密工具')
|
|
39
|
+
parser.add_argument('-key', metavar='K', type=str, \
|
|
40
|
+
help='解密密钥,长度不能超过22个字符,否则,进行左右11个字符截取,格式:[a-zA-Z0-9]+,不得包含特殊字符 decrypt key, length should not exceed 22 characters, otherwise, left and right 11 characters will be intercepted, format: [a-zA-Z0-9]+, no special characters allowed')
|
|
41
|
+
parser.add_argument('-txt', metavar='T', type=str, \
|
|
42
|
+
help='需要解密的字符串 string to be decrypted')
|
|
43
|
+
|
|
44
|
+
key = parser.parse_args().key if parser.parse_args() else ''
|
|
45
|
+
txt = parser.parse_args().txt if parser.parse_args() else ''
|
|
46
|
+
if not key:
|
|
47
|
+
print('\033[31m解密密钥不能为空。\033[0m')
|
|
48
|
+
return
|
|
49
|
+
if not txt:
|
|
50
|
+
print('\033[31m需要解密的字符串不能为空。\033[0m')
|
|
51
|
+
return
|
|
52
|
+
from asterisksecurity.encryption import AsteriskEncrypt
|
|
53
|
+
a = AsteriskEncrypt(key)
|
|
54
|
+
try:
|
|
55
|
+
print(f'解密结果:{a.decrypt(txt)}')
|
|
56
|
+
except Exception as e:
|
|
57
|
+
print(f'\033[31m解密失败:{e}\033[0m')
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
from pyDes import des, CBC, PAD_PKCS5
|
|
2
|
+
import hashlib
|
|
3
|
+
import base64
|
|
4
|
+
|
|
5
|
+
class AsteriskEncrypt():
|
|
6
|
+
'''
|
|
7
|
+
加密类提供了加密和解密的方法
|
|
8
|
+
The encryption class provides encryption and decryption methods.
|
|
9
|
+
在初始化类时需要提供加密和解密的密钥
|
|
10
|
+
The encryption and decryption keys need to be provided when the class is initialized.
|
|
11
|
+
密钥为字符串,不能为“-_”,初始化方法会自动进行密钥处理
|
|
12
|
+
The key is a string and cannot be "-_". The initialization method will automatically process the key.
|
|
13
|
+
加密方法使用了哈希+DES的算法。
|
|
14
|
+
The encryption method uses a hash+DES algorithm.
|
|
15
|
+
构造函数需要输入key字符串,该字符串可以自定义,但是不能包含“-_”字符。
|
|
16
|
+
The constructor needs to input the key string, which can be customized, but cannot contain "-_" characters.
|
|
17
|
+
可以加密包含中文的字符串。
|
|
18
|
+
Strings containing Chinese characters can be encrypted.
|
|
19
|
+
'''
|
|
20
|
+
|
|
21
|
+
def __init__(self, key:str):
|
|
22
|
+
'''
|
|
23
|
+
加密用的key字符串,一般为字母和数字数字
|
|
24
|
+
The key string used for encryption is generally a combination of letters and numbers.
|
|
25
|
+
Args:
|
|
26
|
+
key(str): a-z,A-Z,0-9
|
|
27
|
+
'''
|
|
28
|
+
|
|
29
|
+
# key的字符串长度不能超过22个字符,否则,进行左右11个字符截取
|
|
30
|
+
if not self.__valid_key(key):
|
|
31
|
+
from asterisksecurity.error import InvalidEncriptionKey
|
|
32
|
+
raise InvalidEncriptionKey()
|
|
33
|
+
k_b = len(key)
|
|
34
|
+
if k_b == 22:
|
|
35
|
+
key = key+'=='
|
|
36
|
+
elif k_b > 11:
|
|
37
|
+
key = key[:11] + key[-11:] + '=='
|
|
38
|
+
else:
|
|
39
|
+
key = key + (22-k_b) * '0' + '=='
|
|
40
|
+
|
|
41
|
+
self.key_f = base64.b64decode(key)[:8]
|
|
42
|
+
self.key_b = base64.b64decode(key)[8:]
|
|
43
|
+
|
|
44
|
+
def __valid_key(self, key:str) -> bool:
|
|
45
|
+
"""
|
|
46
|
+
使用正则表达式验证key的格式
|
|
47
|
+
Validate the key format using regular expression.
|
|
48
|
+
Args:
|
|
49
|
+
key(str): The key to be validated. 待验证的key
|
|
50
|
+
Returns:
|
|
51
|
+
bool: True if the key format is valid, False otherwise. 如果key格式有效,则返回True,否则返回False
|
|
52
|
+
"""
|
|
53
|
+
import re
|
|
54
|
+
pattern = r'^[a-zA-Z0-9]+$'
|
|
55
|
+
if re.match(pattern, key):
|
|
56
|
+
return True
|
|
57
|
+
return False
|
|
58
|
+
|
|
59
|
+
def encrypt(self, s:str)->str:
|
|
60
|
+
"""
|
|
61
|
+
加密字符串的方法
|
|
62
|
+
The method of encrypting strings.
|
|
63
|
+
Args:
|
|
64
|
+
s(str):需要加密的字符串 string to be encrypted
|
|
65
|
+
Return:
|
|
66
|
+
str:加密后的字符串 encrypted string
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
m = hashlib.md5()
|
|
70
|
+
m.update(s.encode('utf-8'))
|
|
71
|
+
m_body = m.digest()
|
|
72
|
+
data = str(m_body) + str(s.encode('utf-8'))
|
|
73
|
+
KEY = self.key_f
|
|
74
|
+
IV = self.key_b
|
|
75
|
+
k_des = des(KEY, CBC, IV, pad=None, padmode=PAD_PKCS5)
|
|
76
|
+
des_data = k_des.encrypt(data)
|
|
77
|
+
_final = base64.b64encode(des_data)
|
|
78
|
+
return bytes.decode(_final)
|
|
79
|
+
|
|
80
|
+
def decrypt(self, s:str)->str:
|
|
81
|
+
"""
|
|
82
|
+
encrypt对应的解密方法
|
|
83
|
+
The decryption method corresponding to encrypt.
|
|
84
|
+
Args:
|
|
85
|
+
s(str):加密后的字符串 encrypted string
|
|
86
|
+
Returns:
|
|
87
|
+
str: 解密后的字符串 decrypted string
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
decode_b64 = base64.b64decode(bytes(s, encoding='utf8'))
|
|
91
|
+
KEY = self.key_f
|
|
92
|
+
IV = self.key_b
|
|
93
|
+
k_des = des(KEY, CBC, IV, pad=None, padmode=PAD_PKCS5)
|
|
94
|
+
decode_des = k_des.decrypt(decode_b64)
|
|
95
|
+
i = decode_des.find(b"'",2) + 1
|
|
96
|
+
return bytes(bytes.decode(decode_des[i:]).replace("b'", "").strip("'"),'utf-8').decode('unicode_escape').encode('latin1').decode('utf-8')
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class InvalidEncriptionKey(Exception):
|
|
2
|
+
'''
|
|
3
|
+
Encryption Key accepts a-z, A-Z and 0-9
|
|
4
|
+
'''
|
|
5
|
+
def __init__(self):
|
|
6
|
+
self.message = 'Encryption Key accepts a-z, A-Z and 0-9'
|
|
7
|
+
super().__init__(self.message)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def __str__(self) -> str:
|
|
11
|
+
return f'''{self.__class__.__name__}:{self.message}'''
|