|
@@ -4,7 +4,8 @@ import time
|
|
|
import uuid
|
|
import uuid
|
|
|
|
|
|
|
|
from lib.contract import Contract
|
|
from lib.contract import Contract
|
|
|
-
|
|
|
|
|
|
|
+from cryptography.fernet import Fernet
|
|
|
|
|
+import rsa
|
|
|
|
|
|
|
|
class Transaction:
|
|
class Transaction:
|
|
|
def __init__(self):
|
|
def __init__(self):
|
|
@@ -62,17 +63,39 @@ class Transaction:
|
|
|
return True
|
|
return True
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
+ def file_open(file):
|
|
|
|
|
+ key_file = open(file, 'rb')
|
|
|
|
|
+ key_data = key_file.read()
|
|
|
|
|
+ key_file.close()
|
|
|
|
|
+ return key_data
|
|
|
|
|
+
|
|
|
def hash(self):
|
|
def hash(self):
|
|
|
string_object = json.dumps(self.data, sort_keys=True)
|
|
string_object = json.dumps(self.data, sort_keys=True)
|
|
|
block_string = string_object.encode()
|
|
block_string = string_object.encode()
|
|
|
|
|
|
|
|
- raw_hash = hashlib.sha256(block_string)
|
|
|
|
|
- hex_hash = raw_hash.hexdigest()
|
|
|
|
|
|
|
+ # open the public key file
|
|
|
|
|
+ pubkey = rsa.PublicKey.load_pkcs1(file_open('publickey.key')) #Sender public key - input field neccessary
|
|
|
|
|
+
|
|
|
|
|
+ # create the cipher
|
|
|
|
|
+ cipher = Fernet(pubkey)
|
|
|
|
|
+
|
|
|
|
|
+ # encrypt the data
|
|
|
|
|
+ encrypted_data = cipher.encrypt(block_string)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ #these lines only neccessary for key_encryption - solve the problem of bytes
|
|
|
|
|
+ # open the symmetric key file for encryoting the file
|
|
|
|
|
+ #skey = open('symmetric.key','rb')
|
|
|
|
|
+ #key = skey.read()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ # encrypt the symmetric key file with the public key
|
|
|
|
|
+ #encrypted_key = rsa.encrypt(key,pubkey)
|
|
|
|
|
|
|
|
- self.hash_value = hex_hash
|
|
|
|
|
|
|
+ self.hash_value = encrypted_data
|
|
|
self.log(f'Hashed: {self.hash_value}')
|
|
self.log(f'Hashed: {self.hash_value}')
|
|
|
|
|
|
|
|
- return hex_hash
|
|
|
|
|
|
|
+ return encrypted_data
|
|
|
|
|
|
|
|
def log(self, text):
|
|
def log(self, text):
|
|
|
print(f'[ TRANS ] {text}')
|
|
print(f'[ TRANS ] {text}')
|