Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,6 +21,7 @@ import qr
|
|
| 21 |
import stegan
|
| 22 |
import json
|
| 23 |
import re
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
|
|
@@ -38,48 +39,29 @@ def rsa_encrypt_eth():
|
|
| 38 |
|
| 39 |
|
| 40 |
def rsa_generate():
|
| 41 |
-
|
| 42 |
-
keyPair = RSA.generate(3072)
|
| 43 |
-
print(dir(keyPair))
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
pubKeyPEM = pubKey.exportKey()
|
| 49 |
-
print(pubKeyPEM.decode('ascii'))
|
| 50 |
-
print(f"Private key: (n={hex(pubKey.n)}, d={hex(keyPair.d)})")
|
| 51 |
-
privKeyPEM = keyPair.exportKey()
|
| 52 |
-
print(privKeyPEM.decode('ascii'))
|
| 53 |
-
output = re.search('[0-9a-fA-F]{32}', str(pubKeyPEM))
|
| 54 |
qr_wal=qrx.make(output)
|
| 55 |
qr_wal.save("qr_wal_tmp.png")
|
| 56 |
-
#privcipher = PKCS1_OAEP.new(keyPair)
|
| 57 |
-
#pubcipher = PKCS1_OAEP.new(pubKey)
|
| 58 |
-
out1 = f'{pubKey.n}{keyPair.d}'
|
| 59 |
-
out2 = f'{pubKey.n}{keyPair.e}'
|
| 60 |
-
return privKeyPEM,pubKeyPEM,output,"qr_wal_tmp.png",output
|
| 61 |
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
-
|
| 66 |
-
def rsa_encrypt(msg,pubKey):
|
| 67 |
-
pubKey = pubKey.strip('"')
|
| 68 |
-
key = b64decode(pubKey)
|
| 69 |
-
private_key = RSA.importKey(key)
|
| 70 |
-
#cipher = PKCS1_v1_5.new(private_key)
|
| 71 |
-
cipher = PKCS1_OAEP.new(private_key)
|
| 72 |
|
| 73 |
-
|
|
|
|
|
|
|
| 74 |
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
encryptor = PKCS1_OAEP.new(cipher)
|
| 80 |
-
encrypted = encryptor.encrypt(msg)
|
| 81 |
-
print("Encrypted:", binascii.hexlify(encrypted))
|
| 82 |
-
return binascii.hexlify(encrypted)
|
| 83 |
|
| 84 |
def rsa_decrypt(encrypted,keyPair):
|
| 85 |
decryptor = PKCS1_OAEP.new(keyPair)
|
|
|
|
| 21 |
import stegan
|
| 22 |
import json
|
| 23 |
import re
|
| 24 |
+
import os
|
| 25 |
|
| 26 |
|
| 27 |
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
def rsa_generate():
|
| 42 |
+
key_pair = RSA.generate(1024)
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
public_key = key_pair.publickey().exportKey()
|
| 45 |
+
private_key = key_pair.exportKey()
|
| 46 |
+
output = re.search('[0-9a-fA-F]{32}', str(public_key))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
qr_wal=qrx.make(output)
|
| 48 |
qr_wal.save("qr_wal_tmp.png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
return private_key,public_key,output,"qr_wal_tmp.png",output
|
| 51 |
|
| 52 |
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
|
| 56 |
+
def rsa_encrypt(msg,public_key):
|
| 57 |
+
key = RSA.importKey(public_key)
|
| 58 |
|
| 59 |
+
message = msg.encode()
|
| 60 |
+
print(message)
|
| 61 |
|
| 62 |
+
cipher = PKCS1_OAEP.new(key)
|
| 63 |
+
ciphertext = cipher.encrypt(message)
|
| 64 |
+
return (ciphertext)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
def rsa_decrypt(encrypted,keyPair):
|
| 67 |
decryptor = PKCS1_OAEP.new(keyPair)
|