-2

I want to know where I can find exported keys. I don't see .pem file in my current directory. I am able to save key to txt file but its not working when I am trying to encrypt string using that key. Please help

from Crypto import Random
from Crypto.PublicKey import RSA

def generate_keys():
    modulus_length = 256*4
    keys = RSA.generate(modulus_length, Random.new().read)
    publickey = keys.publickey()

    keys.exportKey(format="PEM")
    publickey.exportKey(format="PEM")

    # with open("prkey","wb") as f:
    #   f.write(keys.exportKey())

    # with open("pvkey","wb") as p:
    #   p.write(publickey.exportKey())


return keys, publickey
amol rane
  • 325
  • 1
  • 13

1 Answers1

1

According to docs the method exportKey() returns "A byte string with the encoded public or private half." So it is up to you as a programmer to save it somewhere.

This is done by the code, you have commented out.

DonPaulie
  • 2,004
  • 17
  • 26