Skip to content

Commit

Permalink
fix bug: setup:readme.md util:encrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
CAOLINAN committed May 24, 2018
1 parent 6d95f54 commit 8598349
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

base_dir = os.path.abspath(os.path.dirname(__file__))
# Get the long description from the README file
with open(os.path.join(base_dir, 'README.md'), 'rb') as f:
with open(os.path.join(base_dir, 'read.md'), 'rb') as f:
long_description = f.read().decode('utf-8')


Expand Down
14 changes: 7 additions & 7 deletions ulordapi/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# coding=utf-8
# Copyright (c) 2016-2018 The Ulord Core Developers
# @File : config.py
# @Author: PuJi
# @Date : 2018/5/16 0016

# @Description : Second import.Just after utils
import os, json, logging, io, time

from ulordapi.utils import fileHelper
from ulordapi import utils


Expand Down Expand Up @@ -87,8 +87,9 @@ def edit(self, data):


baseconfig = Config(
version="0.0.1",
config_file=os.path.join(ROOTPATH, 'config')
version="0.0.1",
Debug=True,
config_file=os.path.join(ROOTPATH, 'config')
)


Expand Down Expand Up @@ -159,14 +160,13 @@ def edit(self, data):

# encryption
# utilspath = os.path.join(os.getcwd(), 'utils'),
pubkeypath=os.path.join(os.path.join(os.getcwd(), 'utils'), 'public.pem'),
privkeypath=os.path.join(os.path.join(os.getcwd(), 'utils'), 'private.pem'),
pubkeypath=os.path.join(os.getcwd(), 'public.pem'),
privkeypath=os.path.join(os.getcwd(), 'private.pem'),
)


dbconfig = Config(
IsCreated=False,
Debug=True,
SECRET_KEY="ulord platform is good",
SQLALCHEMY_DATABASE_URI='sqlite:///sqlite.db',
SQLALCHEMY_COMMIT_ON_TEARDOWN=True,
Expand Down
10 changes: 8 additions & 2 deletions ulordapi/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,14 @@ def __init__(self, appkey, secret):
Developer.__init__(self, appkey, secret)
self.log = logging.getLogger("Developer2:")
self.log.info("Developer2 init")
self.pripath = os.path.join(os.getcwd(), 'private.pem')
self.pubpath = os.path.join(os.getcwd(), 'public.pem')
if webconfig.get('privkeypath'):
self.pripath = webconfig.get('privkeypath')
else:
self.pripath = os.path.join(os.getcwd(), 'private.pem')
if webconfig.get('pubkeypath'):
self.pubpath = webconfig.get('pubkeypath')
else:
self.pubpath = os.path.join(os.getcwd(), 'public.pem')
self.rsahelper = utils.RSAHelper(self.pubpath, self.pripath)

def get_purearg(self, arg):
Expand Down
37 changes: 29 additions & 8 deletions ulordapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# @File : utils.py
# @Author: Ulord_PuJi
# @Date : 2018/5/18 0018
# @Description: project import first.Alone.

import re, os, hashlib, base64, logging, json, codecs, collections

Expand All @@ -11,6 +12,9 @@
from Crypto import Random


RANDOM_GENERATOR=Random.new().read


def isCellphone(number):
"""
check if a cellphone
Expand Down Expand Up @@ -97,6 +101,7 @@ def __init__(self, public_path, private_path):
else:
self.generate()
self.load()
# update public pem path and private pem path

def generate(self):
"""
Expand Down Expand Up @@ -130,20 +135,36 @@ def _encry(self, comment):
:type comment: str
:return: encrypted information
"""
cipher = PKCS1_v1_5.new(self.pubkey)
return (cipher.encrypt(comment))
pass

def encry(self, pubkey, comment):
cipher = PKCS1_v1_5.new(pubkey)
return (cipher.encrypt(comment))
# cipher = PKCS1_v1_5.new(pubkey)
# return (cipher.decrypt(base64.b64decode(comment), RANDOM_GENERATOR))
pass

def _decrypt(self, message):
pass
"""
decrypt message
:param message: need to be decrypted
:type message: str
:return: decrypted message
"""
cipher = PKCS1_v1_5.new(self.privkey)
return (cipher.decrypt(base64.b64decode(message), RANDOM_GENERATOR))

def decrypt(self, prikey, message):
# cipher = PKCS1_v1_5.new(prikey)
# return (cipher.decrypt(base64.b64decode(message), RANDOM_GENERATOR))
pass
"""
using private key to decrypt message
:param prikey: private key
:type prikey: str
:param message: need to be decrypted
:type message: str
:return: decrypted message
"""
cipher = PKCS1_v1_5.new(prikey)
return (cipher.decrypt(base64.b64decode(message), RANDOM_GENERATOR))


class FileHelper():
Expand Down

0 comments on commit 8598349

Please sign in to comment.