|
@@ -6,8 +6,10 @@ import os
|
|
|
|
|
|
|
|
from create_keys import make_keys
|
|
from create_keys import make_keys
|
|
|
from lib.contract import Contract
|
|
from lib.contract import Contract
|
|
|
-from cryptography.fernet import Fernet
|
|
|
|
|
-import rsa
|
|
|
|
|
|
|
+from cryptography.hazmat.backends import default_backend
|
|
|
|
|
+from cryptography.hazmat.primitives import serialization
|
|
|
|
|
+from cryptography.hazmat.primitives import hashes
|
|
|
|
|
+from cryptography.hazmat.primitives.asymmetric import padding
|
|
|
|
|
|
|
|
class Transaction:
|
|
class Transaction:
|
|
|
def __init__(self):
|
|
def __init__(self):
|
|
@@ -71,7 +73,11 @@ class Transaction:
|
|
|
make_keys(recipient)
|
|
make_keys(recipient)
|
|
|
|
|
|
|
|
with open(path, 'rb') as f:
|
|
with open(path, 'rb') as f:
|
|
|
- return rsa.PublicKey.load_pkcs1(f.read())
|
|
|
|
|
|
|
+ public_key = serialization.load_pem_public_key(
|
|
|
|
|
+ f.read(),
|
|
|
|
|
+ backend=default_backend()
|
|
|
|
|
+ )
|
|
|
|
|
+ return public_key
|
|
|
|
|
|
|
|
# key_file = open(file, 'rb')
|
|
# key_file = open(file, 'rb')
|
|
|
# key_data = key_file.read()
|
|
# key_data = key_file.read()
|
|
@@ -84,13 +90,15 @@ class Transaction:
|
|
|
|
|
|
|
|
# open the public key file
|
|
# open the public key file
|
|
|
pubkey = self.get_keys(recipient) #Sender public key - input field neccessary
|
|
pubkey = self.get_keys(recipient) #Sender public key - input field neccessary
|
|
|
- print(pubkey)
|
|
|
|
|
- # create the cipher
|
|
|
|
|
- cipher = Fernet(pubkey)
|
|
|
|
|
-
|
|
|
|
|
- # encrypt the data
|
|
|
|
|
- encrypted_data = cipher.encrypt(block_string)
|
|
|
|
|
|
|
|
|
|
|
|
+ encrypted_data = pubkey.encrypt(
|
|
|
|
|
+ block_string,
|
|
|
|
|
+ padding.OAEP(
|
|
|
|
|
+ mgf=padding.MGF1(algorithm=hashes.SHA256()),
|
|
|
|
|
+ algorithm=hashes.SHA256(),
|
|
|
|
|
+ label=None
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
#these lines only neccessary for key_encryption - solve the problem of bytes
|
|
#these lines only neccessary for key_encryption - solve the problem of bytes
|
|
|
# open the symmetric key file for encryoting the file
|
|
# open the symmetric key file for encryoting the file
|