Skip to content

Instantly share code, notes, and snippets.

@subintp
Created March 23, 2016 05:54
Show Gist options
  • Save subintp/97f87b76ed9a4985c354 to your computer and use it in GitHub Desktop.
Save subintp/97f87b76ed9a4985c354 to your computer and use it in GitHub Desktop.
RSA/ECB with PKCS1 padding in Python
import rsa
import base64
# modulus in integer
MODULUS = 123456789996582395910301286053968077124788323801012630967456380836472396333396466272319708473453610663848909708214595391668878270127153659315097128748348977528953482874935452127643776505027944666257946919553474879512809890824078158244248097149714260265207481163611166304138228724039676901039297181889888815151
# exponent in integer
EXPONENT = 65537
PUBLIC_KEY = rsa.PublicKey(MODULUS, EXPONENT)
class Encryptor:
@staticmethod
def encrypt(message):
message = message.encode('utf8')
crypto = base64.b64encode(rsa.encrypt(message, PUBLIC_KEY)) # encodes encrypted message in Base64 also
return crypto
@AakashCode12
Copy link

Thanks was stuck in this error for 4-5 hours. Really appreciate it

@alt-fox
Copy link

alt-fox commented Aug 3, 2022

works great :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment