Skip to content

Instantly share code, notes, and snippets.

@cfitz
Last active December 27, 2018 17:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfitz/4553167fe7fd9447145a901fe90986c2 to your computer and use it in GitHub Desktop.
Save cfitz/4553167fe7fd9447145a901fe90986c2 to your computer and use it in GitHub Desktop.
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5 as Cipher_PKCS1_v1_5
from base64 import b64decode
# uses pycryptodome (3.7.2)
file_in = open('private.pem','rb').read()
key = RSA.import_key(file_in) # import the public key
# we make our cipher
cipher = Cipher_PKCS1_v1_5.new(key)
msg = open('message.txt', 'rb').read()
decrypt_text = cipher.decrypt(b64decode(msg), None).decode()
print("here's our message:", decrypt_text)
from Crypto.PublicKey import RSA
import urllib.parse
# uses pycryptodome (3.7.2)
# We make the key and save the private key somewhere super safe.
key = RSA.generate(2048)
print("Dumping PEM file to private.pem.")
f = open('private.pem','wb')
f.write(key.export_key('PEM'))
f.close
# This is where users need to go to approve the app and get their base64 encoded
# token info
public_key = urllib.parse.quote_plus(key.publickey().exportKey().decode('utf-8'))
url = 'https://stage.neurostars.org/user-api-key/new?scopes=write&application_name=HelpMe&public_key={0}&client_id=helpme-alpha&nonce=666401a65ea121858be20f0925524453'.format(public_key.replace("'", ""))
print(url)
print("Please go to the above URL, Enter/Paste your key. Ctrl-D to save it.")
contents = []
while True:
try:
line = input()
except EOFError:
break
contents.append(line)
msg = '\n'.join(contents)
print("Dumping our payload to message.txt")
f = open('message.txt','w')
f.write(msg)
f.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment