Skip to content

Instantly share code, notes, and snippets.

@kavishkagihan
Last active November 29, 2021 18:05
Show Gist options
  • Save kavishkagihan/8f09757d76ad753e7bebbdf231d96c38 to your computer and use it in GitHub Desktop.
Save kavishkagihan/8f09757d76ad753e7bebbdf231d96c38 to your computer and use it in GitHub Desktop.
from Crypto.PublicKey import RSA
from base64 import b64encode as b64
def int2bytes(number):
return number.to_bytes((number.bit_length() + 7) // 8, byteorder="big")
fp = open("publickey.crt", "r")
key = RSA.importKey(fp.read())
fp.close()
n = b64(int2bytes(key.n)).decode()
e = b64(int2bytes(key.e)).decode()
print("n:", n.replace('+', '-').replace('/', '_'))
print("e:", e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment