-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRSA.py
32 lines (25 loc) · 998 Bytes
/
RSA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import rsa
class RSA:
def __init__(self):
# self.message = message.encode()
self.msg_encrypted = b''
self.msg_decrypted = b''
def encryption(self, message):
# public_key, private_key = rsa.newkeys(1024)
# with open('private_key.pem', 'wb') as f:
# f.write(private_key.save_pkcs1('PEM'))
#
# with open('public_key.pem', 'wb') as f:
# f.write(public_key.save_pkcs1('PEM'))
with open('public_key.pem', 'rb') as f:
public_key = rsa.PublicKey.load_pkcs1(f.read())
self.msg_encrypted += rsa.encrypt(message, public_key)
print(self.msg_encrypted)
return [self.msg_encrypted]
def decryption(self, msg_encrypted):
with open('private_key.pem', 'rb') as f:
private_key = rsa.PrivateKey.load_pkcs1(f.read())
msg_decrypted = rsa.decrypt(msg_encrypted, private_key)
return msg_decrypted.decode()
if __name__ == '__main__':
RSA()