caPrivKeyPEM := new(bytes.Buffer)
pem.Encode(caPrivKeyPEM, &pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(caKey),
})
if err := ioutil.WriteFile(path + "ca.key", caPEM.Bytes(), 0644); err != nil {
log.Printf("Write the CA certificate file error: %v\n", err)
return nil, nil, err
}
I suspect the caPrivKeyPEM.Bytes() rather than the caPEM.Bytes() should be written to ca.key.