Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,7 +22,7 @@ def calculate_hash(data, hash_function: str = "sha256") -> str:
|
|
| 22 |
return h.hexdigest()
|
| 23 |
|
| 24 |
|
| 25 |
-
def
|
| 26 |
key = RSA.generate(2048)
|
| 27 |
private_key = key.export_key('PEM')
|
| 28 |
file_out = open("private.pem", "wb")
|
|
@@ -41,7 +41,7 @@ def generate_keys1():
|
|
| 41 |
|
| 42 |
return public_key,private_key,address_im,address
|
| 43 |
|
| 44 |
-
def
|
| 45 |
data = data.encode("utf-8")
|
| 46 |
#data = "I met aliens in UFO. Here is the map.".encode("utf-8")
|
| 47 |
file_out = open("encrypted_data.bin", "wb")
|
|
@@ -68,7 +68,7 @@ def encrypt_text1(data,in2,address):
|
|
| 68 |
file.close()
|
| 69 |
return str(file_data),enc_qr
|
| 70 |
|
| 71 |
-
def
|
| 72 |
enc_in = stegan2.decode(im)
|
| 73 |
private_key = RSA.import_key(open("private.pem").read())
|
| 74 |
enc_session_key = enc_in[:private_key.size_in_bytes()]
|
|
@@ -96,14 +96,15 @@ def decrypt_text1(im,in2):
|
|
| 96 |
|
| 97 |
|
| 98 |
with gr.Blocks() as app:
|
| 99 |
-
|
| 100 |
-
seed = gr.Textbox(label='Seed Phrase')
|
| 101 |
with gr.Row():
|
| 102 |
gr.Column()
|
| 103 |
with gr.Column():
|
| 104 |
with gr.Box():
|
| 105 |
with gr.Row():
|
| 106 |
with gr.Column():
|
|
|
|
|
|
|
| 107 |
out1 = gr.Textbox(label='Private Key')
|
| 108 |
out2 = gr.Textbox(label='Public Key')
|
| 109 |
img3=gr.Pil()
|
|
@@ -115,7 +116,9 @@ with gr.Blocks() as app:
|
|
| 115 |
rsa_dec_btn = gr.Button("RSA Decrypt")
|
| 116 |
rsa_dec_mes = gr.Textbox(label="decoded")
|
| 117 |
gr.Column()
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
| 120 |
app.launch()
|
| 121 |
|
|
|
|
| 22 |
return h.hexdigest()
|
| 23 |
|
| 24 |
|
| 25 |
+
def generate_keys():
|
| 26 |
key = RSA.generate(2048)
|
| 27 |
private_key = key.export_key('PEM')
|
| 28 |
file_out = open("private.pem", "wb")
|
|
|
|
| 41 |
|
| 42 |
return public_key,private_key,address_im,address
|
| 43 |
|
| 44 |
+
def encrypt_text(data,in2,address):
|
| 45 |
data = data.encode("utf-8")
|
| 46 |
#data = "I met aliens in UFO. Here is the map.".encode("utf-8")
|
| 47 |
file_out = open("encrypted_data.bin", "wb")
|
|
|
|
| 68 |
file.close()
|
| 69 |
return str(file_data),enc_qr
|
| 70 |
|
| 71 |
+
def decrypt_text(im,in2):
|
| 72 |
enc_in = stegan2.decode(im)
|
| 73 |
private_key = RSA.import_key(open("private.pem").read())
|
| 74 |
enc_session_key = enc_in[:private_key.size_in_bytes()]
|
|
|
|
| 96 |
|
| 97 |
|
| 98 |
with gr.Blocks() as app:
|
| 99 |
+
|
|
|
|
| 100 |
with gr.Row():
|
| 101 |
gr.Column()
|
| 102 |
with gr.Column():
|
| 103 |
with gr.Box():
|
| 104 |
with gr.Row():
|
| 105 |
with gr.Column():
|
| 106 |
+
gen_wal_btn=gr.Button()
|
| 107 |
+
seed = gr.Textbox(label='Seed Phrase')
|
| 108 |
out1 = gr.Textbox(label='Private Key')
|
| 109 |
out2 = gr.Textbox(label='Public Key')
|
| 110 |
img3=gr.Pil()
|
|
|
|
| 116 |
rsa_dec_btn = gr.Button("RSA Decrypt")
|
| 117 |
rsa_dec_mes = gr.Textbox(label="decoded")
|
| 118 |
gr.Column()
|
| 119 |
+
|
| 120 |
+
gen_wal_btn.click(generate_keys,None,[out2,out1, img3,out3])
|
| 121 |
+
rsa_enc_btn.click(encrypt_text,[rsa_to_enc,out2,out3],[rsa_enc_mes,qr_enc_mes])
|
| 122 |
+
rsa_dec_btn.click(decrypt_text,[qr_enc_mes,out1],rsa_dec_mes)
|
| 123 |
app.launch()
|
| 124 |
|