【问题标题】:Go: Load certificate so it becomes a *x509.Certificate (that is able to sign other certificates)Go:加载证书,使其成为 *x509.Certificate(能够签署其他证书)
【发布时间】:2014-10-20 00:02:24
【问题描述】:

我已经用 golang-nuts 询问过,但没有回应

https://groups.google.com/forum/#!topic/golang-nuts/EhlpMiMAPSM

我认为复制邮件正文没有多大意义,因为我不相信 Google 群组或链接会改变,第一封电子邮件的正文就足够了。

我有一个使用 x509 包生成的证书,该 CA 证书由另一个也使用 x509 包生成的 CA 证书签名。 一口气完成。

打开文件 使用 x509.CreateCertificate() 创建 der 用 pem.Encode() 编组 pem

CA 证书是有效的,在各种浏览器中导入也没有任何投诉

openssl -text 也报告可解析

我试过 tls.LoadX509KeyPair() 和

func LoadX509KeyPair(certFile, keyFile string) (*x509.Certificate, *rsa.PrivateKey) {
    cf, e := ioutil.ReadFile(certFile)
    if e != nil {
        fmt.Println("cfload:", e.Error())
        os.Exit(1)
    }

    kf, e := ioutil.ReadFile(keyFile)
    if e != nil {
        fmt.Println("kfload:", e.Error())
        os.Exit(1)
    }
    cpb, cr := pem.Decode(cf)
    fmt.Println(string(cr))
    kpb, kr := pem.Decode(kf)
    fmt.Println(string(kr))
    crt, e := x509.ParseCertificate(cpb.Bytes)

    if e != nil {
        fmt.Println("parsex509:", e.Error())
        os.Exit(1)
    }
    key, e := x509.ParsePKCS1PrivateKey(kpb.Bytes)
    if e != nil {
        fmt.Println("parsekey:", e.Error())
        os.Exit(1)
    }
    return crt, key
}

然而,

parsex509: asn1: 语法错误:数据被截断 退出状态 1

如何加载证书以便我可以使用它以 *x509.Certificate 类型签署其他证书?

我可能缺少一些明显的东西,但它是什么?

【问题讨论】:

  • Darko 回答了你的问题。
  • 我是 Darko 还是你的意思是你回答了它,因为我没有收到邮件和/或邮件存档没有更新

标签: go x509


【解决方案1】:

答案是:问题中的做法是正确的做法。

问题或错误仍然存​​在于证书创建中,因此在“如何加载证书”问题的范围内,该问题得到了解答。

【讨论】:

    猜你喜欢
    • 2015-04-29
    • 2014-12-30
    • 1970-01-01
    • 2020-07-16
    • 2014-06-17
    • 1970-01-01
    • 2014-10-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多