rsa key conversion

751 views
Skip to first unread message

Jonathan Pittman

unread,
Dec 10, 2011, 10:39:07 PM12/10/11
to golan...@googlegroups.com
If I have a public key that looks like this:

AAAAB3NzaC1yc2EAAAADAQABAAACAQCuRSC4mHvWiwu2oHbnBM9iYkeZ2+Jv5ZgXRLzIV/Gz7Kikvm5w4EKAZkfQXRsqVE9wRiCHKFyGLshuWLYQw60VRCJrJUFfjmrxHTtcV9KwxKFaonWljv3rDBPQ8718AlyXocm+f5k8NkrYRFH1SSXWx0kpCZYyD+1RweiqsX5DmIOzZsjNLa83Z3PaCveY91PRRrsbG8bf23GbXiDssoGR/JkYPipIXWcgc9JtDz6F/TNSsAeYenAucdAOJ00ck652c8u7MG6pmcwtbB2b3B4KhpnGfltTXL4pEhIERhiYuL12ARd8xGrbC1YIb0A53Oy5MOaEhcKMxgcOSzAmCQvFTMtaUNx+9F7/qGDQNXWHypPeIp9ftyUGAxSFkD8chzny/CJw+VOGL7IFGlYZPqDFI4edT0/KiEJjAusi4Uyy8q+nvFu2ESF/RWeLr2JxpVaUoSQ/0Wq9WFh6fT81bf040KYx33suAiKgCgsHZmBfyX+mi9TzLqK+lJQIQ9W/3QFJOXq4S3mPVbfdNbmR08miboZWHn/gcfAvdTBVh/Wx9QHGkhSw8VELDIoLA49/0wvqt2aZXJJtPm8Izj5orLbQktSo4Ud41gIXQklv8nQbtge4y/RZ9qSMpuhduusVmCzN4Ef9+p7GAXz1fiHBINSC0QL4Uqt8munoOWnjF48HWw==

How would I convert that to an rsa.PublicKey from the crypto/rsa package?

kortschak

unread,
Dec 11, 2011, 7:24:47 PM12/11/11
to golang-nuts
It looks like you might be able to find relevant code in exp/ssh.

Jonathan Pittman

unread,
Dec 11, 2011, 8:44:43 PM12/11/11
to kortschak, golang-nuts
The only thing I found so far will convert a private key file to an rsa.PrivateKey that also contains an rsa.PublicKey.  However, I have not found anything that converts a public key file (or bytes from an ssh-agent) into an rsa.PublicKey.

kortschak

unread,
Dec 11, 2011, 8:57:04 PM12/11/11
to golang-nuts
I think there are at least private functions that you can use to make
your own parser function:

http://weekly.golang.org/src/pkg/exp/ssh/server.go#L89
http://weekly.golang.org/src/pkg/exp/ssh/common.go#L18
http://weekly.golang.org/src/pkg/exp/ssh/messages.go#L417
http://weekly.golang.org/src/pkg/exp/ssh/messages.go#L381


On Dec 12, 11:44 am, Jonathan Pittman


<jonathan.mark.pitt...@gmail.com> wrote:
> The only thing I found so far will convert a private key file to an
> rsa.PrivateKey that also contains an rsa.PublicKey.  However, I have not
> found anything that converts a public key file (or bytes from an ssh-agent)
> into an rsa.PublicKey.
>

Jonathan Pittman

unread,
Dec 12, 2011, 1:06:10 AM12/12/11
to kortschak, golang-nuts
That did help!  I had to piece the parts together (as you suggested), but I finally found the missing pieces to my puzzle.  Thanks!

steve...@gmail.com

unread,
Jun 14, 2013, 11:19:57 AM6/14/13
to golan...@googlegroups.com
Can you maybe publish the code you used to do this?

The links someone replied to you below here are dead.

Thanks

Michael Gehring

unread,
Jun 15, 2013, 5:29:48 AM6/15/13
to steve...@gmail.com, golan...@googlegroups.com

Jonathan Pittman

unread,
Jun 15, 2013, 9:33:30 PM6/15/13
to Michael Gehring, steve...@gmail.com, golang-nuts
If you just want something to do it for you, after you decode the base64 form, use the exported ssh.ParsePublicKey.  If you want to know how to do this, you can read through the code Michael linked.  And ssh.ParseAuthorizedKey will handle parsing an rsa.PublicKey from an authorized_keys file (including the base64 decoding).

All of this is in that same keys.go file.  So, there is not much of a rabbit hole to follow.

I hope that helps!


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Reply all
Reply to author
Forward
0 new messages