I have an object rsa.PublicKey(derived from rsa.PrivateKey). And I'm trying to export it to OpenSSH format to display it on a web page.
I noticed go.crypto / ssh library which seems to be doing this.
And there’s a discussion about this implementation (this is actually exactly what I need to do)
Unfortunately, I got a little stuck as the byte array returned in an unknown encoding, and I can't just convert it to a string to display it.
func PublicKey(rsaKey rsa.PublicKey) string {
key, _ := ssh.NewPublicKey(&rsaKey)
marshalled := ssh.MarshalPublicKey(key)
return string(marshalled)
}
This is similar to what it adds ssh-rsaat the beginning of the line. However, most characters are not recognized.
Here's the byte array that I retrieve for the public lambda key:
[0 0 0 7 115 115 104 45 114 115 97 0 0 0 3 1 0 1 0 0 0 65 0 178 153 15 73 196 125 250 140 212 0 174 106 77 27 138 59 106 19 100 43 35 242 139 0 59 251 151 121 10 222 154 76 200 43 139 42 129 116 125 222 192 139 98 150 229 58 8 195 49 104 126 242 92 75 244 147 107 161 192 230 4 30 157 21]
?