I need to generate publickey from a private key without temporary location locally like we do in sshgen.So i use this.Here iam passing my private key as input like this(while executing):
python codekey.py "-----BEGIN RSA PRIVATE KEY-----\nMIhhhhhhhhhhhhhhhh......Bidqt/YS3/0giWrtv+rMkJtv8n\nmirJ+16SZodI5gMuknvZG....................n-----END RSA PRIVATE KEY-----"
My code (codekey.py):
import sys
import io
from twisted.conch.ssh import keys
k = sys.argv[1]
rsa = keys.RSA.importKey(k)
key = keys.Key(rsa)
ssh_public = key.public().toString("openssh")
print ssh_public
error:
Traceback (most recent call last):
File "codekey.py", line 7, in <module>
rsa = keys.RSA.importKey(k)
File "/usr/lib/python2.7/dist-packages/Crypto/PublicKey/RSA.py", line 638, in importKey
if lines[1].startswith(b('Proc-Type:4,ENCRYPTED')):
IndexError: list index out of range
Dyanamically i need to pass key value as shown above while executing my python script and from that it will generate public key .Whether it is possible ??,i dont need to store locally,since for priveleges and key securities,dont want to hack.