Spaces:
Runtime error
Runtime error
Update app_og.py
Browse files
app_og.py
CHANGED
|
@@ -27,8 +27,11 @@ def calculate_hash(data, hash_function: str = "sha256") -> str:
|
|
| 27 |
|
| 28 |
|
| 29 |
def generate_keys():
|
|
|
|
| 30 |
key = RSA.generate(2048)
|
| 31 |
-
private_key = key.export_key('PEM')
|
|
|
|
|
|
|
| 32 |
print(f'private_key:: {private_key}')
|
| 33 |
|
| 34 |
file_out_priv = open("private.pem", "wb")
|
|
@@ -84,7 +87,7 @@ def encrypt_text(data,pub_im,priv_im,address):
|
|
| 84 |
#print(f'priv_key:: {priv_key}')
|
| 85 |
#private_key = RSA.import_key(priv_key)
|
| 86 |
data = data.encode("utf-8")
|
| 87 |
-
data = sign(data,priv_im)
|
| 88 |
|
| 89 |
|
| 90 |
recipient_key = RSA.import_key(pub_key)
|
|
@@ -132,11 +135,11 @@ def encrypt_text(data,pub_im,priv_im,address):
|
|
| 132 |
|
| 133 |
def decrypt_text(im,in2):
|
| 134 |
enc_in = stegan2.decode(im)
|
| 135 |
-
|
| 136 |
#private_key = RSA.import_key(open("private.pem").read())
|
| 137 |
priv_key = stegan2.decode(in2)
|
| 138 |
print(f'priv_key:: {priv_key}')
|
| 139 |
-
private_key = RSA.import_key(priv_key)
|
| 140 |
print(f'private_key:: {private_key}')
|
| 141 |
enc_session_key = enc_in[:private_key.size_in_bytes()]
|
| 142 |
end1 = private_key.size_in_bytes()+16
|
|
@@ -159,14 +162,17 @@ def decrypt_text(im,in2):
|
|
| 159 |
cipher_aes = AES.new(session_key, AES.MODE_EAX, nonce)
|
| 160 |
data = cipher_aes.decrypt_and_verify(ciphertext, tag)
|
| 161 |
|
| 162 |
-
public_key = private_key.publickey().export_key('PEM')
|
| 163 |
-
data_val = data[0]
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
#transaction
|
| 168 |
|
| 169 |
-
print (pkcs1_15.new(public_key).verify(transaction_hash, signature))
|
| 170 |
return(data.decode("utf-8"))
|
| 171 |
|
| 172 |
def test_fn(im1,im2):
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
def generate_keys():
|
| 30 |
+
secret_code="password"
|
| 31 |
key = RSA.generate(2048)
|
| 32 |
+
#private_key = key.export_key('PEM')
|
| 33 |
+
private_key = key.export_key(passphrase=secret_code, pkcs=8,
|
| 34 |
+
protection="scryptAndAES128-CBC")
|
| 35 |
print(f'private_key:: {private_key}')
|
| 36 |
|
| 37 |
file_out_priv = open("private.pem", "wb")
|
|
|
|
| 87 |
#print(f'priv_key:: {priv_key}')
|
| 88 |
#private_key = RSA.import_key(priv_key)
|
| 89 |
data = data.encode("utf-8")
|
| 90 |
+
#data = sign(data,priv_im)
|
| 91 |
|
| 92 |
|
| 93 |
recipient_key = RSA.import_key(pub_key)
|
|
|
|
| 135 |
|
| 136 |
def decrypt_text(im,in2):
|
| 137 |
enc_in = stegan2.decode(im)
|
| 138 |
+
secret_code="password"
|
| 139 |
#private_key = RSA.import_key(open("private.pem").read())
|
| 140 |
priv_key = stegan2.decode(in2)
|
| 141 |
print(f'priv_key:: {priv_key}')
|
| 142 |
+
private_key = RSA.import_key(priv_key,passphrase=secret_code)
|
| 143 |
print(f'private_key:: {private_key}')
|
| 144 |
enc_session_key = enc_in[:private_key.size_in_bytes()]
|
| 145 |
end1 = private_key.size_in_bytes()+16
|
|
|
|
| 162 |
cipher_aes = AES.new(session_key, AES.MODE_EAX, nonce)
|
| 163 |
data = cipher_aes.decrypt_and_verify(ciphertext, tag)
|
| 164 |
|
| 165 |
+
#public_key = private_key.publickey().export_key('PEM')
|
| 166 |
+
#data_val = data[0]
|
| 167 |
+
#print (data_val)
|
| 168 |
+
|
| 169 |
+
#signature = data[1]
|
| 170 |
+
#print (signature)
|
| 171 |
+
#transaction_hash = SHA256.new(data)
|
| 172 |
|
| 173 |
#transaction
|
| 174 |
|
| 175 |
+
#print (pkcs1_15.new(public_key).verify(transaction_hash, signature))
|
| 176 |
return(data.decode("utf-8"))
|
| 177 |
|
| 178 |
def test_fn(im1,im2):
|