def generate_platform_root_key(self): data = { 'uid': self.uid, '_id': 'platform', 'exp': int(time.time()) + SIGNATURE_DURATION } return utils.encrypt(data)
def register(): db = DB() print(request.data) print(request.data.decode()) data = json.loads(request.data.decode()) print(data) if not db.isExist(data['username']): username = data['username'] salt = os.urandom(16) password = encrypt(data['password'], salt) email = data['email'] print('DEBUG: Ready to create doc') if db.newDoc( dict(_id=username, salt=base64.b64encode(salt).decode(), password=base64.b64encode(password).decode(), email=email)): response = make_response("OK") return response # return 'OK' else: response = make_response("An Error occured on the server") return response # return 'An Error occured on the server' else: response = make_response("Username Exists") return response
def serialize(self, user, role): message = user.get_message(self.oid, role) key = utils.encrypt(message) return { 'oid': self.oid, 'labels': self.labels, 'properties': dict(self.__node__), 'key': key, 'role': role }
def login(): print(request.data) print(request.data.decode()) data = json.loads(request.data.decode()) db = DB() if not db.isExist(data['username']): response = make_response("No such username") return response res = db.findDoc(data['username']) print(base64.b64decode(res['salt'].encode())) print(base64.b64decode(res['password'].encode())) tmp = encrypt(data['password'], base64.b64decode(res['salt'].encode())) if base64.b64encode(tmp).decode() == res['password']: session['login'] = True response = make_response("OK") return response else: response = make_response("Password Wrong") return response
def generate_app_key(self, app): role = self.get_role(app) message = self.get_message(app.aid, role) app_key = utils.encrypt(message) return app_key
def last_name_value(self, last_name): self.last_name = encrypt(last_name)
def first_name_value(self, first_name): self.first_name = encrypt(first_name)
def test_encrypt_and_decrypt(): msg = 'my very secret message' code = utils.encrypt(msg) assert type(code) is str assert msg == utils.decrypt(code)