views:

58

answers:

2

... or if not, can you provide me link or RFC number to full algorithm (from getting ASCII encoded Private key file/string to generation of ASCII encoded public key file/string).

To show you a bigger picture - I started using a pylibssh2 library. This library has a method - userauth_publickey_fromfile (it raises NotImplementedException, but when you force launching python binding - it works). The problem is that this method wants private key (good) and public key (hell knows why). Of course, I can pass both of those keys as argumets to my functions, but I think it is unnecessary, and I don't want to expect one more variable just for that. So I want to generate public key from private one by myself.

Maybe I'm missing something in pylibssh2 or even in libssh2 itself (I can write bindings for that as well) ?

Thanks for any help!

+1  A: 

Do you need the answer to be strictly python? You can do this with ssh-keygen -y -f privatekey

Daenyth
Yes, I know. But I'm trying to avoid any external commands or shell executions.
liadan
A: 

I don't know how you get userauth_publickey_fromfile() working, but according to http://github.com/wallix/pylibssh2/blob/master/libssh2/session.py, this method expects paths of key files, not the keys themselves.

If the private key is yours, then both - the public and private key - should reside in your ~/.ssh directory.

Private and public keys can only be created in pairs. If you could manage to derive one of them from the other, an cryptographic universe would explode.

The public key must be made available to the other side of the SSH connection. Therefore this method expects it in addition to the private key.

Bernd Petersohn