Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ from Crypto.Random import get_random_bytes
|
|
| 4 |
from Crypto.Cipher import AES, PKCS1_OAEP
|
| 5 |
from Crypto.Hash import RIPEMD160, SHA256
|
| 6 |
import base58
|
| 7 |
-
|
| 8 |
import stegan2
|
| 9 |
import qr
|
| 10 |
|
|
@@ -25,21 +25,24 @@ def calculate_hash(data, hash_function: str = "sha256") -> str:
|
|
| 25 |
def generate_keys():
|
| 26 |
key = RSA.generate(2048)
|
| 27 |
private_key = key.export_key('PEM')
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
public_key = key.publickey().export_key('PEM')
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
|
|
|
|
|
|
|
|
|
|
| 37 |
hash_1 = calculate_hash(public_key, hash_function="sha256")
|
| 38 |
hash_2 = calculate_hash(hash_1, hash_function="ripemd160")
|
| 39 |
address = base58.b58encode(hash_2)
|
| 40 |
address_im=qr.make_qr(txt=address)
|
| 41 |
|
| 42 |
-
return public_key,private_key,address_im,address
|
| 43 |
|
| 44 |
def encrypt_text(data,in2,address):
|
| 45 |
data = data.encode("utf-8")
|
|
@@ -105,9 +108,11 @@ with gr.Blocks() as app:
|
|
| 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()
|
| 111 |
out3 = gr.Textbox(label='Address')
|
| 112 |
rsa_to_enc = gr.Textbox(label="txt to encrypt")
|
| 113 |
rsa_enc_btn = gr.Button("RSA Encrypt")
|
|
@@ -117,7 +122,7 @@ with gr.Blocks() as app:
|
|
| 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()
|
|
|
|
| 4 |
from Crypto.Cipher import AES, PKCS1_OAEP
|
| 5 |
from Crypto.Hash import RIPEMD160, SHA256
|
| 6 |
import base58
|
| 7 |
+
import stegan
|
| 8 |
import stegan2
|
| 9 |
import qr
|
| 10 |
|
|
|
|
| 25 |
def generate_keys():
|
| 26 |
key = RSA.generate(2048)
|
| 27 |
private_key = key.export_key('PEM')
|
| 28 |
+
file_out_priv = open("private.pem", "wb")
|
| 29 |
+
file_out_priv.write(private_key)
|
| 30 |
+
file_out_priv.close()
|
| 31 |
|
| 32 |
public_key = key.publickey().export_key('PEM')
|
| 33 |
+
file_out_pub = open("receiver.pem", "wb")
|
| 34 |
+
file_out_pub.write(public_key)
|
| 35 |
+
file_out_pub.close()
|
| 36 |
|
| 37 |
+
qr_link="test"
|
| 38 |
+
priv_key = stegan.conv_im("private_key.png",data=file_out_priv)
|
| 39 |
+
pub_key = stegan.conv_im("public_key.png",data=file_out_pub)
|
| 40 |
hash_1 = calculate_hash(public_key, hash_function="sha256")
|
| 41 |
hash_2 = calculate_hash(hash_1, hash_function="ripemd160")
|
| 42 |
address = base58.b58encode(hash_2)
|
| 43 |
address_im=qr.make_qr(txt=address)
|
| 44 |
|
| 45 |
+
return public_key,private_key,address_im,address,priv_key,pub_key
|
| 46 |
|
| 47 |
def encrypt_text(data,in2,address):
|
| 48 |
data = data.encode("utf-8")
|
|
|
|
| 108 |
with gr.Column():
|
| 109 |
gen_wal_btn=gr.Button()
|
| 110 |
seed = gr.Textbox(label='Seed Phrase')
|
| 111 |
+
img1=gr.Pil(label='Private Key')
|
| 112 |
out1 = gr.Textbox(label='Private Key')
|
| 113 |
+
img2=gr.Pil(label='Public Key')
|
| 114 |
out2 = gr.Textbox(label='Public Key')
|
| 115 |
+
img3=gr.Pil(label='Address')
|
| 116 |
out3 = gr.Textbox(label='Address')
|
| 117 |
rsa_to_enc = gr.Textbox(label="txt to encrypt")
|
| 118 |
rsa_enc_btn = gr.Button("RSA Encrypt")
|
|
|
|
| 122 |
rsa_dec_mes = gr.Textbox(label="decoded")
|
| 123 |
gr.Column()
|
| 124 |
|
| 125 |
+
gen_wal_btn.click(generate_keys,None,[out2,out1, img3,out3,img1,img2])
|
| 126 |
rsa_enc_btn.click(encrypt_text,[rsa_to_enc,out2,out3],[rsa_enc_mes,qr_enc_mes])
|
| 127 |
rsa_dec_btn.click(decrypt_text,[qr_enc_mes,out1],rsa_dec_mes)
|
| 128 |
app.launch()
|