Exemple #1
0
def getUserCredentials():
    global _email
    global _password
    
    email = common.getSetting('email')
    password = common.getSetting('password')
    if email and password:
        _email = enc.decrypt(email)
        _password = enc.decrypt(password)
Exemple #2
0
def getUserCredentials():
    global _email
    global _password

    email = common.getSetting('email')
    password = common.getSetting('password')
    if email and password:
        _email = enc.decrypt(email)
        _password = enc.decrypt(password)
Exemple #3
0
def decrypt_file():
    pw = request.form['pw']
    passward = enc.getKey(pw)
    filename = request.form['filename']
    enc.decrypt(passward, './upload/file/' + filename + '.enc')
    return send_file('./upload/file/' + filename + '.enc.dec',
                     mimetype='text/txt',
                     attachment_filename=filename,
                     as_attachment=True)
def open_keyfile(password):
    with open("ckeys.hash", "r") as f:
        hash = f.readlines()
    f.close()
    with open("ckeys", 'rb') as in_file:
        keys = enc.decrypt(in_file, password)
        if hashlib.sha1(keys).hexdigest() != hash[0]:
            return ""
        else:
            return binascii.hexlify(keys)
    in_file.close()
Exemple #5
0
def download(file_name):
    # Download a file
    remote_file_name = base64.b64encode(enc.siv_encrypt(pbkey1, pbkey2, file_name, ""))
    f2 = '/' + remote_file_name + ".key"
    fx1 = '/' + remote_file_name + ".contents"
    down_thread = Thread(target=download_proxy, args=(fx1,))
    down_thread.start()
    c2 = dpbx_client.get_file(f2).read()
    down_thread.join()
    hash_and_key = enc.decrypt(pbkey4, c2)
    hash_r = hash_and_key[AES_BLOCK_SIZE:]
    key = hash_and_key[:AES_BLOCK_SIZE]
    hash2 = hmac.new(pbkey3, cx1+remote_file_name+key, hashlib.sha256).digest()
    if (hash_r != hash2):
        print hash_r.encode("hex"), hash2.encode("hex"), "Ciphertext has been corrupted"
        return
    contents = enc.decrypt(key, cx1)
    outf = open(file_name, "wb")
    outf.write(contents)
    outf.close()
    print file_name + " has been downloaded."
Exemple #6
0
def get_result(adminsk):
    votelist = []
    with open('temp/Blockchain.dat', 'rb') as blockfile:
        gen = pickle._load(blockfile)
        while True:
            try:
                block = pickle._load(blockfile)
                votelist.extend(block.data)
            except EOFError:
                break
    candy = []
    for vote in votelist:
        votedata_key = bytes(vote['Key'], 'utf-8')
        aeskey = enc.decrypt(adminsk, votedata_key)
        unlocked = aes.decrypt(bytes(vote['Vote Data'], 'utf-8'), aeskey)
        unlocked = str(unlocked)[2:-1]
        votedata = unlocked.split('***')
        votedata[1] = int(votedata[1])
        candy.append(votedata[1])

    return candy
Exemple #7
0
			print('data: '+str(data))
			gpsdata = data['data']
			print('gpsdata: '+str(gpsdata))
			dataList = gpsdata.split(',')
			print('dataList length: '+str(len(dataList)))
			try :
				if len(dataList) == 3:
					lon = str(dataList[0])
					lat = str(dataList[1])
					charge = str(dataList[2])
					timestamp = int(time.time())
					#print('time: '+str(time))
					#print('lon: '+lon)
					#print('lat: '+lat)
					#print('c: '+charge)
					#print('---------------')
					gps = '{"data":"'+lon+','+lat+','+charge+'","published_at":"'+str(timestamp)+'"}'
					print(gps)
					gps_aes = enc.encrypt(gps,str(pword))
					print("aes: "+str(gps_aes))
					result = oraclesio.write2oracle(CHAIN, ORCLID, bytes.decode(gps_aes))
					while result == 'error':
						time.sleep(30)
						result = oraclesio.write2oracle(CHAIN, ORCLID, bytes.decode(gps_aes))
						print(result)	
					print('bytes.decode(aes): '+bytes.decode(gps_aes))
					gps_dec = enc.decrypt(gps_aes,pword)
					print('dec: '+bytes.decode(gps_dec))
			except Exception as e:
				print(e)
				pass
Exemple #8
0
    l = ['eee9ca050b625c9a8206beb29e5687d915f70aaa061993d9ea5bdf2041c66a26', 1, time.time()]
    #--all 3 elements of votedata appended together as a string and hashed
    #--hash converted to bytes
    #--then signed by voter's private key
    #--then appended back to the list
    l.append(enc.sign(voterpriv,bytes(sha256(str('---'.join(str(x) for x in l)).encode('utf-8')).hexdigest(),'utf-8')))
    #--now the list elements are again appended together as string and encrypted
    #--using the shared key
    #--this encrypted data is to be added to vote pool and sent to other as well.
    #--and the key must be encrypted by RSA algotithm using the public key of admin(reciever)

    vote = {'data': encrypt('***'.join(str(i) for i in l),get_private_key(pw)), 'key': enc.encrypt(adminpub,get_private_key(pw))}
    print(vote)
    #--decrypt key
    deckey = enc.decrypt(adminpriv,vote['key'])

    decrypted = decrypt(vote['data'],get_private_key(pw)).decode('utf-8')
    print(decrypted)
    ourdata = decrypted.split('***')
    ourdata[1] = int(ourdata[1])
    ourdata[2] = float(ourdata[2])
    ourdata[3] = bytes(((ourdata[3].replace('b\'','')).replace('\'','')),'utf-8')

    # First let us encrypt secret message
    # encrypted = encrypt("This is a secret message", pw)
    # print(encrypted)
    #
    #
    # # Let us decrypt using our original password
    # decrypted = decrypt(encrypted, pw)
Exemple #9
0
except IOError as e:
    print("Oracle Tx ID not set!")

try:
    with open(CONFIGDIR + 'chain.gps', 'r') as file:
        CHAIN = file.read()
except IOError as e:
    print("CHAIN not set!")

chosen_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID)
batonutxo = chosen_info['registered'][0]['batontxid']
try:
    num = 1
    sample = getconf.oraclessamples_rpc(CHAIN, ORCLID, batonutxo, num)
    print(json.dumps(sample['samples'][0][0]))
    dec = enc.decrypt(str.encode(sample['samples'][0][0]), pword)
    msg = bytes.decode(dec)
    msg2 = msg.replace("'", "\"")
    data = json.loads(msg2)
    dataList = data['data'].split(',')
    timestamp = int(time.time())
    lon = dataList[0]
    lat = dataList[1]
    charge = dataList[2]
except IOError as e:
    print(e)
    lon = 56
    lat = 95
    charge = 100
    pass
while True:
Exemple #10
0
    def default(self, token):
        gpsdata = ""
        try:
            with open(CONFIGDIR + 'gps.pgs', 'r') as file:
                pword = file.read()
        except IOError as e:
            print("Password not set or access denied!")

        try:
            with open(CONFIGDIR + 'orclid.gps', 'r') as file:
                ORCLID = file.read()
        except IOError as e:
            print("Oracle Tx ID not set!")

        try:
            with open(CONFIGDIR + 'chain.gps', 'r') as file:
                CHAIN = file.read()
        except IOError as e:
            print("CHAIN not set!")
        chosen_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID)
        batonutxo = chosen_info['registered'][0]['batontxid']
        name = chosen_info['name']
        funds = '{:.2f}'.format(float(chosen_info['registered'][0]['funds']))
        publisher = chosen_info['registered'][0]['publisher']
        print("name: " + str(name))
        print("funds: " + str(funds))
        print("publisher: " + str(publisher))
        if float(funds) < 200:
            amount = 5
            print("adding oracle funds")
            result = getconf.oraclessubscribe_rpc(CHAIN, ORCLID, publisher,
                                                  amount)
            print(result)
            print("oracle funds added!")
            chosen_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID)
            funds = '{:.2f}'.format(
                float(chosen_info['registered'][0]['funds']))
            print("Oracle funds: " + funds)
        num = 99
        samples = getconf.oraclessamples_rpc(CHAIN, ORCLID, batonutxo, num)
        num_samples = len(samples['samples'])
        print("num_samples: " + str(num_samples))
        leaflet_data = []
        points = []
        lastpoint = ""
        lastcharge = ""
        bounds = ""
        view = ""
        point_var = ""
        opac = 0.99
        i = 0
        for sample in samples['samples']:
            try:
                dec = enc.decrypt(str.encode(sample[0]), pword)
                msg = bytes.decode(dec)
                msg2 = msg.replace("'", "\"")
                data = json.loads(msg2)
                dataList = data['data'].split(',')
                timestamp = data['published_at']
                try:
                    timestamp = datetime.utcfromtimestamp(float(
                        timestamp)).strftime('%Y-%m-%d %H:%M:%S') + " UTC"
                except Exception as e:
                    timestamp = data['published_at']
                    pass

                if lastpoint == "":
                    print("adding first point")
                    print('time: ' + str(timestamp))
                    print('lon: ' + dataList[0])
                    print('lat: ' + dataList[1])
                    print('c: ' + dataList[2])
                    lastpoint = makePoint([dataList[0], dataList[1]],
                                          'skrunch', str(timestamp),
                                          'lastping', '1')
                    bounds = "" + str(dataList[0]) + "," + str(
                        dataList[1]) + "," + str(dataList[0]) + "," + str(
                            dataList[1]) + ""
                    view = "" + dataList[0] + "," + dataList[1] + ""
                    lastcharge = dataList[2]
                elif (float(dataList[1]) > lon_max
                      or float(dataList[1]) < lon_min
                      or float(dataList[0]) > lat_max
                      or float(dataList[0]) < lat_min):
                    point_var += makePoint([dataList[0], dataList[1]], 'paw',
                                           str(timestamp), 'paws', str(opac))
                    leaflet_data.append(
                        json.loads('{"time":"' + timestamp + '", "lat":' +
                                   dataList[1] + ', "lon":' + dataList[0] +
                                   ',"charge":' + dataList[2] + '}'))
                    opac -= 0.01
                    points.append([dataList[0], dataList[1]])
            except Exception as e:
                print(e)
        #print("point_var: "+str(point_var))
        try:
            if 1 != 1:
                underlay1 = makeLines('UNDERLAY_VAR1', 'UNDERLAY_1',
                                      points[0:11], '#ffffff', '4.2', '0.7',
                                      '30', 'underlay')
                underlay2 = makeLines('UNDERLAY_VAR2', 'UNDERLAY_2',
                                      points[10:22], '#ffffff', '4', '0.7',
                                      '30', 'underlay')
                underlay3 = makeLines('UNDERLAY_VAR3', 'UNDERLAY_3',
                                      points[21:33], '#ffffff', '3.8', '0.7',
                                      '30', 'underlay')
                underlay4 = makeLines('UNDERLAY_VAR4', 'UNDERLAY_4',
                                      points[32:44], '#ffffff', '3.6', '0.7',
                                      '30', 'underlay')
                underlay5 = makeLines('UNDERLAY_VAR5', 'UNDERLAY_5',
                                      points[43:55], '#ffffff', '3.4', '0.7',
                                      '30', 'underlay')
                underlay6 = makeLines('UNDERLAY_VAR6', 'UNDERLAY_6',
                                      points[54:66], '#ffffff', '2.6', '0.7',
                                      '30', 'underlay')
                underlay7 = makeLines('UNDERLAY_VAR7', 'UNDERLAY_7',
                                      points[65:77], '#ffffff', '2', '0.7',
                                      '30', 'underlay')
                underlay8 = makeLines('UNDERLAY_VAR8', 'UNDERLAY_8',
                                      points[76:88], '#ffffff', '2', '0.7',
                                      '30', 'underlay')
                underlay9 = makeLines('UNDERLAY_VAR9', 'UNDERLAY_9',
                                      points[87:99], '#ffffff', '2', '0.7',
                                      '30', 'underlay')
                track1 = makeLines('TRACK_VAR1', 'TRACK_1', points[0:11],
                                   '#667DFF', '2.2', '0.7', '30', 'dogtracks')
                track2 = makeLines('TRACK_VAR2', 'TRACK_2', points[10:22],
                                   '#057DFF', '2', '0.7', '30', 'dogtracks')
                track3 = makeLines('TRACK_VAR3', 'TRACK_3', points[21:33],
                                   '#057DFF', '1.8', '0.7', '30', 'dogtracks')
                track4 = makeLines('TRACK_VAR4', 'TRACK_4', points[32:44],
                                   '#057DFF', '1.6', '0.7', '30', 'dogtracks')
                track5 = makeLines('TRACK_VAR5', 'TRACK_5', points[43:55],
                                   '#057DFF', '1.4', '0.7', '30', 'dogtracks')
                track6 = makeLines('TRACK_VAR6', 'TRACK_6', points[54:66],
                                   '#057DFF', '1.2', '0.7', '30', 'dogtracks')
                track7 = makeLines('TRACK_VAR7', 'TRACK_7', points[65:77],
                                   '#057DFF', '1', '0.7', '30', 'dogtracks')
                track8 = makeLines('TRACK_VAR8', 'TRACK_8', points[76:88],
                                   '#057DFF', '1', '0.7', '30', 'dogtracks')
                track9 = makeLines('TRACK_VAR9', 'TRACK_9', points[87:99],
                                   '#057DFF', '1', '0.7', '30', 'dogtracks')
        except Exception as e:
            raise e

        try:
            with open(HTMLDIR + 'scrunch.html', 'r') as file:
                print("Populating template")
                numPoints = len(points)
                print("numPoints: " + str(numPoints))
                dh_map = file.read()
                if 1 != 1:
                    dh_map = dh_map.replace('UNDERLAY_VAR1', underlay1)
                    dh_map = dh_map.replace('UNDERLAY_VAR2', underlay2)
                    dh_map = dh_map.replace('UNDERLAY_VAR3', underlay3)
                    dh_map = dh_map.replace('UNDERLAY_VAR4', underlay4)
                    dh_map = dh_map.replace('UNDERLAY_VAR5', underlay5)
                    dh_map = dh_map.replace('UNDERLAY_VAR6', underlay6)
                    dh_map = dh_map.replace('UNDERLAY_VAR7', underlay7)
                    dh_map = dh_map.replace('UNDERLAY_VAR8', underlay8)
                    dh_map = dh_map.replace('UNDERLAY_VAR9', underlay9)
                    dh_map = dh_map.replace('TRACK_VAR1', track1)
                    dh_map = dh_map.replace('TRACK_VAR2', track2)
                    dh_map = dh_map.replace('TRACK_VAR3', track3)
                    dh_map = dh_map.replace('TRACK_VAR4', track4)
                    dh_map = dh_map.replace('TRACK_VAR5', track5)
                    dh_map = dh_map.replace('TRACK_VAR6', track6)
                    dh_map = dh_map.replace('TRACK_VAR7', track7)
                    dh_map = dh_map.replace('TRACK_VAR8', track8)
                    dh_map = dh_map.replace('TRACK_VAR9', track9)
                dh_map = dh_map.replace('BOUNDS_VAR', bounds)
                dh_map = dh_map.replace('SETVEIW_VAR', view)
                dh_map = dh_map.replace('CHARGE_VAR', lastcharge)
                dh_map = dh_map.replace('POINTS_VAR', point_var)
                dh_map = dh_map.replace('LASTPOINT_VAR', lastpoint)
                dh_map = dh_map.replace('FUNDS_VAR', funds)

                #print(dh_map)
        except IOError as e:
            print("Password not set or access denied!")

        return dh_map
Exemple #11
0
import enc

key = "1234567890123456"
e = enc.cipher(key)
d = enc.cipher(key)
plain = "asfadsfasljasldkasdlfkasdkfnlkjfasjlkdsf"
data = enc.encrypt(e, plain)
plain2 = enc.decrypt(d, data)
print(plain2)
Exemple #12
0
 def dec(self, data: bytes) -> bytes:
     c = self.get_cipher()
     return decrypt(c, data)
    def default(self, token):
        gpsdata = ""
        try:
            with open(CONFIGDIR + 'gps.pgs', 'r') as file:
                pword = file.read()
        except IOError as e:
            print("Password not set or access denied!")

        try:
            with open(CONFIGDIR + 'orclid.gps', 'r') as file:
                ORCLID = file.read()
        except IOError as e:
            print("Oracle Tx ID not set!")

        try:
            with open(CONFIGDIR + 'chain.gps', 'r') as file:
                CHAIN = file.read()
        except IOError as e:
            print("CHAIN not set!")
        chosen_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID)
        batonutxo = chosen_info['registered'][0]['batontxid']
        name = chosen_info['name']
        funds = '{:.2f}'.format(float(chosen_info['registered'][0]['funds']))
        publisher = chosen_info['registered'][0]['publisher']
        print("name: " + str(name))
        print("funds: " + str(funds))
        print("publisher: " + str(publisher))
        if float(funds) < 200:
            amount = 50
            result = getconf.oraclessubscribe_rpc(CHAIN, ORCLID, publisher,
                                                  amount)
            print("oracle funds added!")
            chosen_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID)
            funds = '{:.2f}'.format(
                float(chosen_info['registered'][0]['funds']))
            print("Oracle funds: " + funds)
        num = 99
        samples = getconf.oraclessamples_rpc(CHAIN, ORCLID, batonutxo, num)
        num_samples = len(samples['samples'])
        print("num_samples: " + str(num_samples))
        leaflet_data = []
        points = []
        lastpoint = ""
        lastcharge = ""
        bounds = ""
        view = ""
        point_var = ""
        opac = 0.99
        i = 0
        for sample in samples['samples']:
            try:
                dec = enc.decrypt(str.encode(sample[0]), pword)
                msg = bytes.decode(dec)
                msg2 = msg.replace("'", "\"")
                data = json.loads(msg2)
                dataList = data['data'].split(',')
                timestamp = data['published_at']
                #print('time: '+timestamp)
                timestamp = datetime.utcfromtimestamp(
                    float(timestamp)).strftime('%Y-%m-%d %H:%M:%S') + " UTC"
                #print('time: '+str(timestamp))
                if lastpoint == "":
                    print("adding last point")
                    print('time: ' + str(timestamp))
                    print('lon: ' + dataList[0])
                    print('lat: ' + dataList[1])
                    print('c: ' + dataList[2])
                    lastpoint = makePoint([dataList[0], dataList[1]],
                                          'skrunch', str(timestamp),
                                          'lastping', '1')
                    bounds = "" + str(dataList[0]) + "," + str(
                        dataList[1]) + "," + str(dataList[0]) + "," + str(
                            dataList[1]) + ""
                    view = "" + dataList[0] + "," + dataList[1] + ""
                    lastcharge = dataList[2]
                else:
                    point_var += makePoint([dataList[0], dataList[1]], 'paw',
                                           str(timestamp), 'paws', str(opac))
                    leaflet_data.append(
                        json.loads('{"time":"' + timestamp + '", "lat":' +
                                   dataList[1] + ', "lon":' + dataList[0] +
                                   ',"charge":' + dataList[2] + '}'))
                    opac -= 0.01
                    points.append([dataList[0], dataList[1]])
            except Exception as e:
                print(e)
        numPoints = len(points)
        print("numPoints: " + str(numPoints))
        try:
            with open(HTMLDIR + 'demo.html', 'r') as file:
                dh_map = file.read()
                dh_map = dh_map.replace('BOUNDS_VAR', bounds)
                dh_map = dh_map.replace('SETVEIW_VAR', view)
                dh_map = dh_map.replace('CHARGE_VAR', lastcharge)
                dh_map = dh_map.replace('POINTS_VAR', point_var)
                dh_map = dh_map.replace('LASTPOINT_VAR', lastpoint)
                dh_map = dh_map.replace('FUNDS_VAR', funds)

                #print(dh_map)
        except IOError as e:
            print("Password not set or access denied!")

        return dh_map
Exemple #14
0
			continue
		if low <= number <= high:
			return number
		else:
			print("input outside range, try again")

try:
	with open(CONFIGDIR+'orclid.gps', 'r') as file:
		ORCLID = file.read()
except IOError as e:
	print("Oracle Tx ID not set!")

try:
	with open(CONFIGDIR+'chain.gps', 'r') as file:
		CHAIN = file.read()
except IOError as e:
	print("CHAIN not set!")
chosen_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID)

batonutxo=chosen_info['registered'][0]['batontxid']
num = selectRange(0,999999999,"How many records? ")
samples = getconf.oraclessamples_rpc(CHAIN, ORCLID, batonutxo, num)
for sample in samples['samples']:
	#print(sample[0])
	try:
		dec = enc.decrypt(str.encode(sample[0]), pword)
		#print(dec)
		msg = bytes.decode(dec)
		print(msg)
	except Exception as e:
		pass
def open_keyfile(password,hash):
    with open("ckeys", 'rb') as keyfile:
        keys = enc.decrypt(keyfile, password)
        ok = (hashlib.sha1(keys).hexdigest() == hash)
    keyfile.close()
    return ok
def get_hash(password):
  with open("ckeys", 'rb') as keyfile:
    keys = enc.decrypt(keyfile,password)
    hash = hashlib.sha1(keys).hexdigest()
  keyfile.close()
  return hash