-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryptor.py
More file actions
28 lines (22 loc) · 793 Bytes
/
Encryptor.py
File metadata and controls
28 lines (22 loc) · 793 Bytes
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
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding
with open("E:\\Assignment\\public_key.pem", "rb") as key_file_2:
public_key = serialization.load_pem_public_key(
key_file_2.read(),
backend=default_backend()
)
with open("E:\\Assignment\\Message.txt", "rb") as M:
message = M.read()
print(message)
encrypted = public_key.encrypt(
message,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
)
with open('E:\\Assignment\\Message.encrypted', 'wb') as f:
f.write(encrypted)