I only have a PublicKey string, How do I get the PublicKey Fingerprint?
I have got some idea form https://go-review.googlesource.com/c/crypto/+/32814, but I do not know how to
implement ssh.PublicKey interface.
You probably want to use ssh.ParseAuthorizedKey from the ssh package to load the key:
https://godoc.org/golang.org/x/crypto/ssh#ParseAuthorizedKey
That will give you a public key which you can call ssh.FingerprintLegacyMD5 on in order to get the fingerprint (assuming here you want the md5).
https://godoc.org/golang.org/x/crypto/ssh#FingerprintLegacyMD5 https://godoc.org/golang.org/x/crypto/ssh#FingerprintSHA256
func main() {
// Read a key from a file in authorized keys file line format
// This could be an rsa.pub file or a line from authorized_keys
pubKeyBytes := []byte(`ssh-rsa AAAABMYKEY...ABC [email protected]`)
// Parse the key, other info ignored
pk, _, _, _, err := ssh.ParseAuthorizedKey(pubKeyBytes)
if err != nil {
panic(err)
}
// Get the fingerprint
f := ssh.FingerprintLegacyMD5(pk)
// Print the fingerprint
fmt.Printf("%s\n", f)
}
There are two fingerprint functions provided, not sure which one you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With