-
Notifications
You must be signed in to change notification settings - Fork 210
Encryption
Phil Rukin edited this page Jun 1, 2017
·
3 revisions
The public key is uploaded on web server, and is accessible by everyone. Private key on the other hand is only on bot's side, and only chaos can decrypt messages encrypted with it. Essentially, it's to keep API keys secret, as they cannot be trusted to not be used to take over an account in a public repository.
Public key is available here: http://chaosthebot.com/pubkey.txt
from encryption import decrypt
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives.serialization import load_pem_public_key
pkey = load_pem_public_key(open("server/pubkey.txt", "rb").read(), default_backend())
message = b"Hello, world!"
encrypted = pkey.encrypt(message, padding.OAEP(
padding.MGF1(hashes.SHA1()),
hashes.SHA1(),
None
))
print(decrypt(encrypted)) # b'Hello, world!'