Note that there are some explanatory texts on larger screens.

plurals
  1. POCrypto RSA in Python
    primarykey
    data
    text
    <p>I am checking a code written in Python which is used to generate an RSA public private key pair.</p> <p>It generates the keypair however, at the end of the code it runs ssh-keygen again. I am not sure why that is done. Since, RSA.generate() will itself generate the keypair that we export into two separate files. Why is there a need to run ssh-keygen again?</p> <p>Here are few lines from the code:</p> <pre><code>keypair = RSA.generate(1024, randfunc) with open("pub", "w") as pubfile, open("id_rsa", "w") as privfile: privfile.write(keypair.exportKey()) pubfile.write(keypair.publickey().exportKey()) system("ssh-keygen -m PKCS8 -i -f pub &gt; id_rsa.pub &amp;&amp; rm pub") </code></pre> <p>the file <strong>pub</strong> will store the public key and <strong>id_rsa</strong> will store the private key from the keypair generated by RSA.generate() function.</p> <p>Now, why is it running the ssh-keygen command at the end?</p> <p>Also, it does not take any input file for the -i parameter and -f parameter takes the name pub which was the public key already generated.</p> <p>After executing the code I get two files, id_rsa and id_rsa.pub</p> <p>id_rsa is the private key generated using RSA.generate() but id_rsa.pub stores the result of ssh-keygen command.</p> <p>I need some help to understand the reason for invoking ssh-keygen at the end of the script and also the parameters passed to ssh-keygen. -i should be passed some value and also -f should have output filename and not input.</p> <p><strong>Note:</strong> I read that this is done to convert the public key from OpenSSL format to OpenSSH format using ssh-keygen so that it starts with ssh-rsa instead of BEGIN PUBLIC KEY.</p> <p>Does that mean the format of corresponding private key should also be changed?</p> <p>Since it starts with,</p> <p>BEGIN PRIVATE KEY</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload