Skip to content
Phil Rukin edited this page Jun 1, 2017 · 3 revisions

Encryption

based on the work of @xfix (see #227 and #321)

Encryption mechanics

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

Example

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!'
Clone this wiki locally