![]() ![]() I am creating a private/public key pair, encrypting a message with keys and writing message to a file. Public_key = RSA.import_key(open("mykey.pub").read())Ĭipher_priv = PKCS1_OAEP. RSA encryption and decryption in Python Ask Question Asked 8 years, 1 month ago Modified 7 months ago Viewed 258k times 43 I need help using RSA encryption and decryption in Python. Private_key = RSA.import_key(open("mykey.pem").read()) # It's important to also use our swapped logic in encryption step, otherwise the lib would still use e&n (the private contains all 3 values). Return int(pow(Integer(ciphertext), self._e, self._n))ĭata = "I met aliens in UFO. Return int(pow(Integer(plaintext), self._d, self._n)) So, you could extend the RSA-Key class with that swapped logic, use blackmagic to swap the implementation of the loaded key, and pass it to the normal functions: from import RsaKey This being said, I want to emphasize that I'm not a crypto expert and cannot say for certain that this doesn't compromise security. It is as you say indeed possible to encrypt with private and decrypt with public, the mathematical symmetry in RSA allows just swapping e/d in the keys and then calling the encrypt/decrypt functions. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |