Tutorial :need to create a .pem file



Question:

What the .pem file contain? simply a key or a function which generate the key.

I need to create a .pem file and also need to call this file in a function.

here is code to which I have to proceed:

pk = open( 'public_key.pem', 'rb' ).read()  rsa = M2Crypto.RSA.load_pub_key(pk)  


Solution:1

You can use openssl to create a pem file. You will need to supply it the correct parameters to get the correct type of key. The genkey command of openssl looks like what you want to use.


Solution:2

You can use this code to create a public key pair, then save them unencrypted to two files.

    from M2Crypto import RSA      key=RSA.gen_key(2048, 65537)      key.save_pem('./privkey',cipher=None)      key.save_pub_key('./pubkey')  

To read it, do:

rsa=RSA.load_pub_key('./pubkey')  

And similar if you want to load the private key as well. Good luck!


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »