Skip to content

Instantly share code, notes, and snippets.

@wiktorpp
Created January 16, 2023 18:03
Show Gist options
  • Save wiktorpp/56609de148d6a2983495e742aa038cb2 to your computer and use it in GitHub Desktop.
Save wiktorpp/56609de148d6a2983495e742aa038cb2 to your computer and use it in GitHub Desktop.
python-rsa example usage
import rsa
public, private = rsa.newkeys(512)
# private = rsa.PrivateKey.load_pkcs1(open('private.pem', mode='rb').read())
print(f"Public key: {public}")
print(f"Private key: {private}")
message = b"Hello world!"
encrypted_message = rsa.encrypt(message, public)
print(f"Encrypted message: {encrypted_message.hex()}")
message = rsa.decrypt(encrypted_message, private)
print(f"Decrypted message: {message}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment