

It will also print the following ciphertext to the screen: #OUTPUT If all goes well, the code above will produce two new files on disk in the same folder as the script: public_key.pem and private_key.pem. It will look like gibberish because it is encrypted.

Key = RSA.import_key(open('public_key.pem').read()) Public_key = new_key.publickey().exportKey("PEM")

Then you write the following code: from Crypto.Cipher import PKCS1_OAEP Once you are up to speed, you can jump into the following code to encrypt data with an RSA Public Key, But first, ensure you install the pycryptodomex module: pip install pycryptodomex To understand what we’re doing here, please check out our two foundation tutorials on RSA Encryption: Hi! Let’s encrypt some data using an RSA Public Key Certificate in Python.
