duan117890 2018-03-16 16:29
浏览 221
已采纳

如何在Go中解析RSA公钥?

Why do I get the error ssh: short read from the following code:

package main

import (
    "golang.org/x/crypto/ssh"
    "testing"
)

func TestPublicKeyParsing(t *testing.T) {
    key := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDhZgLqiZYDKCWhyi2gUXIRwIPyMSyXZ6yrwsm3PYfIvFB60kVlNgqDpPVhWoH6eRfaQ1y/xbg4nClZmHEDTvLbTQ1ZoQzzjZ7zvM6aQ4nADmKcCYswEuU94axouVjsHNyMLfOkPXuGec0fChwQ2JDh/B9LCiSDxyhCOgHvETXGXsyBMKjn498iPjJ6snzk35dy5wPZRz41g3dLaygF+wYAT791u/JchHQL7OP7RoNgby+RM16SYZs1tgQVkfU//o+AyTarWYLVDpFU6HPPenE4xEXhbgqd7x3wSNPBsMvY8Zjcu3kdHtboJidyMtKeD8ghV/T24kME58TW15T8Eg8R"

    _, err := ssh.ParsePublicKey([]byte(key))
    if err != nil {
        t.Errorf("ERROR! %s", err)
    }
}

Is the key string in the wrong format?

What is the correct format for the public key?

  • 写回答

1条回答 默认 最新

  • doumu5662 2018-03-16 17:18
    关注

    This looks like the authorized_keys format, which you can parse with ssh.ParseAuthorizedKey.

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

报告相同问题?

悬赏问题

  • ¥15 AE SDK插件开发,获取关键帧值得问题
  • ¥15 谁知道这个咋搞的吗,有偿
  • ¥20 基于spring boot、的scorm
  • ¥15 往复密封问题的两个问题
  • ¥15 DAC函数和STM32
  • ¥15 任务是接收数据并把数据写入DAC7311,这些代码能实现此功能吗
  • ¥15 分析FP -Growth代码运行内存太大而无法运行的原因
  • ¥20 qtcreat 使用msvc编译器开发软件运行时字体锯齿感严重
  • ¥15 为何显示keyerror fruit
  • ¥15 imageware粗糙度表面