开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 11

yg178/Python-SecureHTTP

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
标签 (6)
master
v0.2.4
v0.2.3
v0.2.2
v0.2.1
v0.2.0
v0.1.0
master
分支 (1)
标签 (6)
master
v0.2.4
v0.2.3
v0.2.2
v0.2.1
v0.2.0
v0.1.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
标签 (6)
master
v0.2.4
v0.2.3
v0.2.2
v0.2.1
v0.2.0
v0.1.0
Python-SecureHTTP
/
setup.py
Python-SecureHTTP
/
setup.py
setup.py 5.99 KB
一键复制 编辑 原始数据 按行查看 历史
Mr.tao 提交于 2019年01月17日 10:53 +08:00 . update docs and example
# -*- coding: utf-8 -*-
"""
Python-SecureHTTP
=================
让HTTP传输更加安全,C/S架构的加密通信!(Make HTTP transmissions more secure, encrypted communication for C/S architecture.)
使用概述(Overview)
~~~~~~~~~~~~~~~~~~
**安装(Installation)**
.. code:: bash
$ pip install -U SecureHTTP
**示例代码(Examples)**
1. RSA加密、解密
.. code:: python
from SecureHTTP import AESEncrypt, AESDecrypt
# 加密后的密文
ciphertext = AESEncrypt('ThisIsASecretKey', 'Hello World!')
# 解密后的明文
plaintext = AESDecrypt("ThisIsASecretKey", ciphertext)
2. AES加密、解密
.. code:: python
from SecureHTTP import RSAEncrypt, RSADecrypt, generate_rsa_keys
# 生成密钥对
(pubkey, privkey) = generate_rsa_keys(incall=True)
# 加密后的密文
ciphertext = RSAEncrypt(pubkey, 'Hello World!')
# 解密后的明文
plaintext = RSADecrypt(privkey, ciphertext)
3. C/S加解密示例: `点此查看以下模拟代码的真实WEB环境示例 <https://github.com/staugur/Python-SecureHTTP/blob/master/examples/Demo/>`__
.. code:: python
# 模拟C/S请求
from SecureHTTP import EncryptedCommunicationClient, EncryptedCommunicationServer, generate_rsa_keys
post = {u'a': 1, u'c': 3, u'b': 2, u'data': ["a", 1, None]}
resp = {u'msg': None, u'code': 0}
# 生成密钥对
(pubkey, privkey) = generate_rsa_keys(incall=True)
# 初始化客户端类
client = EncryptedCommunicationClient(pubkey)
# 初始化服务端类
server = EncryptedCommunicationServer(privkey)
# NO.1 客户端加密数据
c1 = client.clientEncrypt(post)
# NO.2 服务端解密数据
s1 = server.serverDecrypt(c1)
# NO.3 服务端返回加密数据
s2 = server.serverEncrypt(resp)
# NO.4 客户端获取返回数据并解密
c2 = client.clientDecrypt(s2)
# 以上四个步骤即完成一次请求/响应
4. B/S加解密示例: `登录时,password使用RSA加密,后端解密 <https://github.com/staugur/Python-SecureHTTP/tree/master/examples/BS-RSA>`__
文档(Documentation)
~~~~~~~~~~~~~~~~~~~
`中文(Chinese) <https://python-securehttp.readthedocs.io/zh_CN/latest/>`__
"""
import os
import re
import ast
import unittest
from setuptools import setup, Command
def test_suite():
test_loader = unittest.TestLoader()
test_suite = test_loader.discover('tests', pattern='test_*.py')
return test_suite
def _get_version():
version_re = re.compile(r'__version__\s+=\s+(.*)')
with open('SecureHTTP.py', 'rb') as fh:
version = ast.literal_eval(version_re.search(fh.read().decode('utf-8')).group(1))
return str(version)
def _get_author():
author_re = re.compile(r'__author__\s+=\s+(.*)')
mail_re = re.compile(r'(.*)\s<(.*)>')
with open('SecureHTTP.py', 'rb') as fh:
author = ast.literal_eval(author_re.search(fh.read().decode('utf-8')).group(1))
return (mail_re.search(author).group(1), mail_re.search(author).group(2))
class PublishCommand(Command):
description = "Publish a new version to pypi"
user_options = [
# The format is (long option, short option, description).
("test", None, "Publish to test.pypi.org"),
("release", None, "Publish to pypi.org"),
]
def initialize_options(self):
"""Set default values for options."""
self.test = False
self.release = False
def finalize_options(self):
"""Post-process options."""
if self.test:
print("V%s will publish to the test.pypi.org" % version)
elif self.release:
print("V%s will publish to the pypi.org" % version)
def run(self):
"""Run command."""
os.system("pip install -U setuptools twine wheel")
os.system("rm -rf build/ dist/ Python_SecureHTTP.egg-info/")
os.system("python setup.py sdist bdist_wheel")
if self.test:
os.system("twine upload --repository-url https://test.pypi.org/legacy/ dist/*")
elif self.release:
os.system("twine upload dist/*")
os.system("rm -rf build/ dist/ Python_SecureHTTP.egg-info/")
if self.test:
print("V%s publish to the test.pypi.org successfully" % version)
elif self.release:
print("V%s publish to the pypi.org successfully" % version)
exit()
version = _get_version()
(author, email) = _get_author()
setup(
name='SecureHTTP',
version=version,
url='https://github.com/staugur/Python-SecureHTTP',
download_url="https://github.com/staugur/Python-SecureHTTP/releases/tag/v%s" % version,
license='MIT',
author=author,
author_email=email,
keywords=["RSA", "AES", "MD5", "HTTP"],
description='Make HTTP transmissions more secure, encrypted communication for C/S architecture.',
long_description=__doc__,
test_suite='setup.test_suite',
py_modules=['SecureHTTP', ],
scripts=["generate_rsa_keys.sh"],
entry_points={
'console_scripts': [
'generate_rsa_keys.py = SecureHTTP:generate_rsa_keys'
]
},
platforms='any',
install_requires=[
'rsa>=4.0',
'pycryptodomex>=3.7.2'
],
tests_require=["flask>0.9"],
cmdclass={
'publish': PublishCommand,
},
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules'
]
)
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

通过使用RSA+AES让HTTP传输更加安全,即C/S架构的加密通信
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/hwsyy/Python-SecureHTTP.git
git@gitee.com:hwsyy/Python-SecureHTTP.git
hwsyy
Python-SecureHTTP
Python-SecureHTTP
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /