dsc80135 2019-08-21 17:55
浏览 1993
已采纳

无法在密钥中找到任何PEM数据

I am trying to run an HTTPS rest server locally. I followed this help: Golang TLS

It works fine when using self-signed certificates as in the above tutorial. But when I replace these certificates with one I generated from GoDaddy for one of my websites, I get ListenAndServe: tls: failed to find any PEM data in key input

These certificates work properly on the apache server but not on my local Go server.

package main
import (
    "log"
    "net/http"
)

func HelloServer(w http.ResponseWriter, req *http.Request) {
    w.Header().Set("Content-Type", "text/plain")
    _, _ = w.Write([]byte("This is an example server.
"))
}

func main() {
    //https://localhost:443/hello
    http.HandleFunc("/hello", HelloServer)
    err := http.ListenAndServeTLS(":443",
        "../../../../../sslcert/server.crt",
        "../../../../../sslcert/server.key",
        nil)
    if err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}
  • 写回答

1条回答 默认 最新

  • duanqian6982 2019-08-22 17:46
    关注

    The issue was with the key file. The beginning of the file had some issue (like UTF-8 BOM at the start of the file or similar) as @SteffenUllrich mentioned. To fix this, I added an empty line just above the key file and it worked.

    Finally, the key looks like:

    <Empty line>
    -----BEGIN RSA PRIVATE KEY-----
    wlWPpSnGEdNjRapfW/6+xzjDVAaKC41c5b07OAviFchwqGI+88
    aZGwBJnTgkbsLddddddd=
    -----END RSA PRIVATE KEY-----
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。