07.07.2023 Views

Implementing-cryptography-using-python

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

230 Chapter 8 ■ Cryptographic Applications and PKI

#The public key in PEM Format

public_key = new_key.publickey().exportKey("PEM")

print (private_key)

fd = open("private_key.pem", "wb")

fd.write(private_key)

fd.close()

print (public_key)

fd = open("public_key.pem", "wb")

fd.write(public_key)

fd.close()

To review the output of the generated keys, see Figure 8.2. The key is in a

special encoded RSA file format. You can decode the file using the following

command:

openssl rsa -in private_key.pem -text -noout

Figure 8.2: Generating RSA certs

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!