瀏覽代碼

feat: add requirements.txt

master
xuxiaofei 4 年之前
父節點
當前提交
f77e608a34
  1. 2
      .pylintrc
  2. 3
      .vscode/settings.json
  3. 26
      common/utils/aes.py
  4. 4
      requirements.txt
  5. 2
      vislib/urls.py
  6. 8
      vislib/views/source.py
  7. 8
      vislib/views/views.py

2
.pylintrc

@ -2,4 +2,4 @@
ignore=migrations
disable=
C0114, # missing-module-docstring
C0114, # missing-module-docstring

3
.vscode/settings.json

@ -0,0 +1,3 @@
{
"python.linting.pylintEnabled": true
}

26
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)
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)

4
requirements.txt

@ -0,0 +1,4 @@
Django==3.0.4
pycryptodome==3.9.8
django-cors-headers==3.2.1
mysqlclient==1.3.13

2
vislib/urls.py

@ -34,4 +34,4 @@ urlpatterns = [
path('source/tables/<uuid:sourceId>', source.sourceTables, name="sourceTables"),
path('source/tables/save', source.sourceTableSave, name="sourceTableSave"),
path('source/tables/<uuid:sourceId>/linked', source.sourceLinkedTables, name="sourceLinkedTables"),
]
]

8
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'
)

8
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'
)

Loading…
取消
儲存