func LoadX509KeyPair(certpath, keypath string) (cert tls.Certificate, err error) { key_buf, err := ioutil.ReadFile(keypath) if err != nil { return } cert_buf, err := ioutil.ReadFile(certpath) if err != nil { return } pkey, err := evp.LoadPrivateKeyPEM(key_buf) if err != nil { return } key_buf, err = pkey.DumpPEM() return tls.X509KeyPair(cert_buf, key_buf) }
func main() { keypath := flag.String("key", "", "The path to a PEM key") flag.Parse() if len(*keypath) == 0 { flag.PrintDefaults() return } buf, err := ioutil.ReadFile(*keypath) if err != nil { panic(err) } key, err := evp.LoadPrivateKeyPEM(buf) if err != nil { panic(err) } buf, err = key.DumpPEM() if err != nil { panic(err) } fmt.Printf("%s", buf) }