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.
转到-如何从PublicKey生成SSH PublicKey指纹,PublicKey的类型可能是[rsa dsa ssh-rsa ssh-dss ecdsa]之一
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
dreinuqm992401 2017-09-26 15:08关注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 me@myplace.local`) // 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 ", f) }There are two fingerprint functions provided, not sure which one you need.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报