Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,11 +47,14 @@ def generate_keys():
|
|
| 47 |
return public_key,private_key,address_im,address,priv_key,pub_key
|
| 48 |
|
| 49 |
def encrypt_text(data,in2,address):
|
|
|
|
|
|
|
| 50 |
data = data.encode("utf-8")
|
| 51 |
#data = "I met aliens in UFO. Here is the map.".encode("utf-8")
|
| 52 |
-
file_out = open("encrypted_data.bin", "wb")
|
| 53 |
|
| 54 |
-
recipient_key = RSA.import_key(open("receiver.pem").read())
|
|
|
|
|
|
|
| 55 |
session_key = get_random_bytes(16)
|
| 56 |
|
| 57 |
# Encrypt the session key with the public RSA key
|
|
@@ -61,6 +64,9 @@ def encrypt_text(data,in2,address):
|
|
| 61 |
# Encrypt the data with the AES session key
|
| 62 |
cipher_aes = AES.new(session_key, AES.MODE_EAX)
|
| 63 |
ciphertext, tag = cipher_aes.encrypt_and_digest(data)
|
|
|
|
|
|
|
|
|
|
| 64 |
[ file_out.write(x) for x in (enc_session_key, cipher_aes.nonce, tag, ciphertext) ]
|
| 65 |
file_out.close()
|
| 66 |
doc_name = "encrypted_data.bin"
|
|
@@ -116,16 +122,22 @@ with gr.Blocks() as app:
|
|
| 116 |
gen_wal_btn=gr.Button()
|
| 117 |
seed = gr.Textbox(label='Seed Phrase')
|
| 118 |
img1=gr.Pil(label='Private Key')
|
| 119 |
-
out1 = gr.Textbox(label='Private Key')
|
| 120 |
img2=gr.Pil(label='Public Key')
|
| 121 |
-
out2 = gr.Textbox(label='Public Key')
|
| 122 |
img3=gr.Pil(label='Address')
|
| 123 |
out3 = gr.Textbox(label='Address')
|
| 124 |
-
rsa_to_enc = gr.Textbox(label="txt to encrypt")
|
| 125 |
-
rsa_enc_btn = gr.Button("RSA Encrypt")
|
| 126 |
-
rsa_enc_mes = gr.Textbox(label="encoded")
|
| 127 |
-
qr_enc_mes = gr.Image(type="filepath")
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
with gr.Tab("Decrypt"):
|
| 130 |
mes_in = gr.Image(label="Message", type="filepath")
|
| 131 |
priv_key_in = gr.Image(label="Private Key", type="filepath")
|
|
@@ -135,6 +147,6 @@ with gr.Blocks() as app:
|
|
| 135 |
gr.Column()
|
| 136 |
|
| 137 |
gen_wal_btn.click(generate_keys,None,[out2,out1, img3,out3,img1,img2])
|
| 138 |
-
rsa_enc_btn.click(encrypt_text,[rsa_to_enc,
|
| 139 |
rsa_dec_btn.click(decrypt_text,[mes_in,priv_key_in],rsa_dec_mes)
|
| 140 |
app.launch()
|
|
|
|
| 47 |
return public_key,private_key,address_im,address,priv_key,pub_key
|
| 48 |
|
| 49 |
def encrypt_text(data,in2,address):
|
| 50 |
+
pub_key = stegan2.decode(in2)
|
| 51 |
+
|
| 52 |
data = data.encode("utf-8")
|
| 53 |
#data = "I met aliens in UFO. Here is the map.".encode("utf-8")
|
|
|
|
| 54 |
|
| 55 |
+
#recipient_key = RSA.import_key(open("receiver.pem").read())
|
| 56 |
+
recipient_key = RSA.import_key(pub_key)
|
| 57 |
+
|
| 58 |
session_key = get_random_bytes(16)
|
| 59 |
|
| 60 |
# Encrypt the session key with the public RSA key
|
|
|
|
| 64 |
# Encrypt the data with the AES session key
|
| 65 |
cipher_aes = AES.new(session_key, AES.MODE_EAX)
|
| 66 |
ciphertext, tag = cipher_aes.encrypt_and_digest(data)
|
| 67 |
+
|
| 68 |
+
file_out = open("encrypted_data.bin", "wb")
|
| 69 |
+
|
| 70 |
[ file_out.write(x) for x in (enc_session_key, cipher_aes.nonce, tag, ciphertext) ]
|
| 71 |
file_out.close()
|
| 72 |
doc_name = "encrypted_data.bin"
|
|
|
|
| 122 |
gen_wal_btn=gr.Button()
|
| 123 |
seed = gr.Textbox(label='Seed Phrase')
|
| 124 |
img1=gr.Pil(label='Private Key')
|
| 125 |
+
out1 = gr.Textbox(label='Private Key',max_lines=4)
|
| 126 |
img2=gr.Pil(label='Public Key')
|
| 127 |
+
out2 = gr.Textbox(label='Public Key',max_lines=4)
|
| 128 |
img3=gr.Pil(label='Address')
|
| 129 |
out3 = gr.Textbox(label='Address')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
+
|
| 132 |
+
with gr.Tab("Encrypt"):
|
| 133 |
+
|
| 134 |
+
rsa_to_enc = gr.Textbox(label="txt to encrypt")
|
| 135 |
+
pub_key_in = gr.Image(label="Public Key", type="filepath")
|
| 136 |
+
rsa_enc_btn = gr.Button("RSA Encrypt")
|
| 137 |
+
rsa_enc_mes = gr.Textbox(label="encoded", max_lines=4)
|
| 138 |
+
qr_enc_mes = gr.Image(type="filepath")
|
| 139 |
+
|
| 140 |
+
|
| 141 |
with gr.Tab("Decrypt"):
|
| 142 |
mes_in = gr.Image(label="Message", type="filepath")
|
| 143 |
priv_key_in = gr.Image(label="Private Key", type="filepath")
|
|
|
|
| 147 |
gr.Column()
|
| 148 |
|
| 149 |
gen_wal_btn.click(generate_keys,None,[out2,out1, img3,out3,img1,img2])
|
| 150 |
+
rsa_enc_btn.click(encrypt_text,[rsa_to_enc,pub_key_in,out3],[rsa_enc_mes,qr_enc_mes])
|
| 151 |
rsa_dec_btn.click(decrypt_text,[mes_in,priv_key_in],rsa_dec_mes)
|
| 152 |
app.launch()
|