|
|
@@ -1,11 +1,10 @@
|
|
|
+from codecs import encode
|
|
|
+import rsa
|
|
|
+from create_keys import get_keys, get_private_key, get_symmetric_key
|
|
|
+from cryptography.fernet import Fernet
|
|
|
from cryptography.hazmat.backends import default_backend
|
|
|
-from cryptography.hazmat.primitives import serialization
|
|
|
-from cryptography.hazmat.primitives import hashes
|
|
|
+from cryptography.hazmat.primitives import hashes, serialization
|
|
|
from cryptography.hazmat.primitives.asymmetric import padding
|
|
|
-from cryptography.fernet import Fernet
|
|
|
-import rsa
|
|
|
-
|
|
|
-from create_keys import get_keys, get_symmetric_key, get_private_key
|
|
|
|
|
|
|
|
|
def encrypt_data(contract, block_string):
|
|
|
@@ -14,18 +13,19 @@ def encrypt_data(contract, block_string):
|
|
|
|
|
|
chiper = Fernet(symmetric_key)
|
|
|
|
|
|
- data = str(chiper.encrypt(block_string))
|
|
|
+ data = str(chiper.encrypt(block_string))[2:-1]
|
|
|
|
|
|
- encrypted_key = str(rsa.encrypt(symmetric_key,pubkey))
|
|
|
+ encrypted_key = str(rsa.encrypt(symmetric_key,pubkey))[2:-1]
|
|
|
+ # encrypted_key = rsa.encrypt(symmetric_key,pubkey)
|
|
|
+ print('ENCRYPTED KEY: ', type(encrypted_key), encrypted_key)
|
|
|
return data, encrypted_key
|
|
|
|
|
|
|
|
|
def decrypt_data(name, t):
|
|
|
- print('DATA OF TRANSACTION: ', type(t.data), t.data)
|
|
|
private_key = get_private_key(name)
|
|
|
- en_key = t.encrypted_key
|
|
|
- print('ENCRYPTED KEY: ', type(en_key), en_key)
|
|
|
+ en_key = encode(t.encrypted_key.encode().decode('unicode_escape'),"raw_unicode_escape")
|
|
|
key = rsa.decrypt(en_key, private_key)
|
|
|
cipher = Fernet(key)
|
|
|
- decrypted_data = cipher.decrypt(t.data)
|
|
|
- print(decrypted_data.decode(), t.data)
|
|
|
+ decrypted_data = cipher.decrypt(bytes(t.data, 'utf-8'))
|
|
|
+ print(decrypted_data)
|
|
|
+ return decrypted_data.decode('utf8').replace("'", '"')
|