duanjia7912 2017-09-26 12:33
浏览 396
已采纳

转到-如何从PublicKey生成SSH PublicKey指纹,PublicKey的类型可能是[rsa dsa ssh-rsa ssh-dss ecdsa]之一

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.

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效