Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -145,9 +145,9 @@ def decrypt_text1(im,in2):
|
|
| 145 |
print(f'mes_bytes3::{mes_bytes3}')
|
| 146 |
print(f'mes_bytes4::{mes_bytes4}')
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
|
| 152 |
|
| 153 |
|
|
@@ -224,10 +224,11 @@ def encrypt(passw,trans_s=None,trans_r=None,trans_a=None):
|
|
| 224 |
if trans_s != None and trans_r != None and trans_a != None and trans_s != "" and trans_r != "" and trans_a != "":
|
| 225 |
trans = trans_block(trans_s,trans_r,trans_a)
|
| 226 |
bytes_j = trans.encode()
|
| 227 |
-
|
| 228 |
-
json_bytes =
|
|
|
|
| 229 |
enc_mes = f'{json_bytes}+ccc+'
|
| 230 |
-
|
| 231 |
#enc_qr = qr.make_qr(txt=(enc_mes.strip('"')))
|
| 232 |
m = hashlib.sha256()
|
| 233 |
bytes_enc_mes = enc_mes.encode()
|
|
@@ -254,6 +255,8 @@ def decrypt(passw,enc_in=None):
|
|
| 254 |
mes1=enc_in.split("+aaa+",1)[0]
|
| 255 |
mes1=mes1.strip("b'").strip("'")
|
| 256 |
mes_bytes = bytes(mes1,'utf-8')
|
|
|
|
|
|
|
| 257 |
mes_dec = fernet.decrypt(mes_bytes).decode()
|
| 258 |
if "+bbb+" in enc_in:
|
| 259 |
mes12=enc_in.split("+aaa+",1)[1]
|
|
@@ -313,7 +316,13 @@ def decrypt(passw,enc_in=None):
|
|
| 313 |
mes14=mes4.strip("b'").strip("'")
|
| 314 |
json_bytes = bytes(mes14,'utf-8')
|
| 315 |
print(f'im_bytes::{json_bytes}')
|
| 316 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
|
| 318 |
|
| 319 |
return(dec_im, mes_dec, dec_json)
|
|
|
|
| 145 |
print(f'mes_bytes3::{mes_bytes3}')
|
| 146 |
print(f'mes_bytes4::{mes_bytes4}')
|
| 147 |
|
| 148 |
+
file_out = open("encrypted_data.bin", "w")
|
| 149 |
+
[ file_out.write(x) for x in (mes_bytes1, mes_bytes2, mes_bytes3, mes_bytes4) ]
|
| 150 |
+
file_out.close()
|
| 151 |
|
| 152 |
|
| 153 |
|
|
|
|
| 224 |
if trans_s != None and trans_r != None and trans_a != None and trans_s != "" and trans_r != "" and trans_a != "":
|
| 225 |
trans = trans_block(trans_s,trans_r,trans_a)
|
| 226 |
bytes_j = trans.encode()
|
| 227 |
+
cipher_rsa = PKCS1_OAEP.new(recipient_key)
|
| 228 |
+
json_bytes = cipher_rsa.encrypt(bytes_j)
|
| 229 |
+
#json_bytes = fernet.encrypt(bytes_j)
|
| 230 |
enc_mes = f'{json_bytes}+ccc+'
|
| 231 |
+
|
| 232 |
#enc_qr = qr.make_qr(txt=(enc_mes.strip('"')))
|
| 233 |
m = hashlib.sha256()
|
| 234 |
bytes_enc_mes = enc_mes.encode()
|
|
|
|
| 255 |
mes1=enc_in.split("+aaa+",1)[0]
|
| 256 |
mes1=mes1.strip("b'").strip("'")
|
| 257 |
mes_bytes = bytes(mes1,'utf-8')
|
| 258 |
+
|
| 259 |
+
|
| 260 |
mes_dec = fernet.decrypt(mes_bytes).decode()
|
| 261 |
if "+bbb+" in enc_in:
|
| 262 |
mes12=enc_in.split("+aaa+",1)[1]
|
|
|
|
| 316 |
mes14=mes4.strip("b'").strip("'")
|
| 317 |
json_bytes = bytes(mes14,'utf-8')
|
| 318 |
print(f'im_bytes::{json_bytes}')
|
| 319 |
+
private_key = RSA.import_key(open("private.pem").read())
|
| 320 |
+
|
| 321 |
+
cipher_rsa = PKCS1_OAEP.new(private_key)
|
| 322 |
+
dec_json = cipher_rsa.decrypt(json_bytes).decode()
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
#dec_json = fernet.decrypt(json_bytes).decode()
|
| 326 |
|
| 327 |
|
| 328 |
return(dec_im, mes_dec, dec_json)
|