我需要从没有临时位置的本地私钥生成公钥,就像我们在 sshgen 中所做的那样。所以我使用 this.Here 我将我的私钥作为这样的输入传递(在执行时):
python codekey.py "-----BEGIN RSA PRIVATE KEY-----\nMIhhhhhhhhhhhhhhhh......Bidqt/YS3/0giWrtv+rMkJtv8n\nmirJ+16SZodI5gMuknvZG....................n-----END RSA PRIVATE KEY-----"
Run Code Online (Sandbox Code Playgroud)
我的代码(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
Run Code Online (Sandbox Code Playgroud)
错误:
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
Run Code Online (Sandbox Code Playgroud)
Dyanamically我需要在执行我的python脚本时传递如上所示的键值,并从中生成公钥。是否可能??,我不需要在本地存储,因为为了特权和关键证券,不想破解。