From f77e608a347740f0ec0ccfc754af7c2decac9ca9 Mon Sep 17 00:00:00 2001 From: xuxiaofei Date: Sat, 19 Sep 2020 15:37:40 +0800 Subject: [PATCH] feat: add requirements.txt --- .pylintrc | 2 +- .vscode/settings.json | 3 +++ common/utils/aes.py | 26 +++++++++++++------------- requirements.txt | 4 ++++ vislib/urls.py | 2 +- vislib/views/source.py | 8 ++++---- vislib/views/views.py | 8 ++++---- 7 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 requirements.txt diff --git a/.pylintrc b/.pylintrc index c99679f..774ff4b 100644 --- a/.pylintrc +++ b/.pylintrc @@ -2,4 +2,4 @@ ignore=migrations disable= - C0114, # missing-module-docstring \ No newline at end of file + C0114, # missing-module-docstring diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..72513b9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.linting.pylintEnabled": true +} \ No newline at end of file diff --git a/common/utils/aes.py b/common/utils/aes.py index 7d8118f..7b06d29 100644 --- a/common/utils/aes.py +++ b/common/utils/aes.py @@ -1,9 +1,9 @@ #!/usr/bin/env python -# -*- coding:utf-8 -*- +# -*- coding:utf-8 -*- #@author: rui.xu #这里使用pycrypto‎库 #按照方法:easy_install pycrypto‎ - + from Crypto.Cipher import AES from binascii import b2a_hex, a2b_hex from django.conf import settings @@ -13,7 +13,7 @@ class prpcrypt(): def __init__(self,key): self.key = key self.mode = AES.MODE_CBC - + #加密函数,如果text不足16位就用空格补足为16位, #如果大于16当时不是16的倍数,那就补足为16的倍数。 def encrypt(self,text): @@ -36,22 +36,22 @@ class prpcrypt(): #因为AES加密时候得到的字符串不一定是ascii字符集的,输出到终端或者保存时候可能存在问题 #所以这里统一把加密后的字符串转化为16进制字符串 return b2a_hex(self.ciphertext) - + #解密后,去掉补足的空格用strip() 去掉 def decrypt(self,text): cryptor = AES.new(self.key,self.mode,b'0000000000000000') plain_text = cryptor.decrypt(a2b_hex(text)).decode("utf8") return plain_text.rstrip('\0') - + pc = prpcrypt(settings.CRYPT_KEY.encode('utf8')) #初始化密钥 if __name__ == '__main__': # for test - print(settings.CRYPT_KEY) - pc = prpcrypt(settings.CRYPT_KEY.encode('utf8')) #初始化密钥 - import sys - str = sys.argv[1] - e = pc.encrypt(str) #加密 - print("加密:",e) - d = pc.decrypt(e) #解密 - print("解密:",d) \ No newline at end of file + print(settings.CRYPT_KEY) + pc = prpcrypt(settings.CRYPT_KEY.encode('utf8')) #初始化密钥 + import sys + str = sys.argv[1] + e = pc.encrypt(str) #加密 + print("加密:",e) + d = pc.decrypt(e) #解密 + print("解密:",d) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..fca8246 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +Django==3.0.4 +pycryptodome==3.9.8 +django-cors-headers==3.2.1 +mysqlclient==1.3.13 diff --git a/vislib/urls.py b/vislib/urls.py index 0a001c5..136d452 100644 --- a/vislib/urls.py +++ b/vislib/urls.py @@ -34,4 +34,4 @@ urlpatterns = [ path('source/tables/', source.sourceTables, name="sourceTables"), path('source/tables/save', source.sourceTableSave, name="sourceTableSave"), path('source/tables//linked', source.sourceLinkedTables, name="sourceLinkedTables"), -] \ No newline at end of file +] diff --git a/vislib/views/source.py b/vislib/views/source.py index 7ba2dcf..2537263 100644 --- a/vislib/views/source.py +++ b/vislib/views/source.py @@ -113,10 +113,10 @@ def sourceTables(request, sourceId): print(password) db=_mysql.connect( - host=host, - port=int(port), - user=username, - passwd=password, + host=host, + port=int(port), + user=username, + passwd=password, db=database, charset='utf8' ) diff --git a/vislib/views/views.py b/vislib/views/views.py index df3fd13..d0de850 100644 --- a/vislib/views/views.py +++ b/vislib/views/views.py @@ -33,10 +33,10 @@ def execSql(request): database = source['database'] db=_mysql.connect( - host=host, - port=int(port), - user=username, - passwd=password, + host=host, + port=int(port), + user=username, + passwd=password, db=database, charset='utf8' )