func GenerateSelfSignedCACertAndKey(CN string) ([]byte, []byte, error) {
	caKey, err := rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		return nil, nil, err
	}

	now := time.Now()
	caCrt := x509.Certificate{
		SerialNumber: big.NewInt(rd.Int63()),
		Subject: pkix.Name{
			CommonName: CN,
		},
		NotBefore:             now.UTC(),
		NotAfter:              now.AddDate(10, 0, 0).UTC(),
		KeyUsage:              x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
		BasicConstraintsValid: true,
		IsCA:                  true,
	}

	caCrtBuf, err := x509.CreateCertificate(rand.Reader, &caCrt, &caCrt, caKey.Public(), caKey)
	if err != nil {
		return nil, nil, err
	}
	caCrtByte := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: caCrtBuf})
	caKeyByte := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(caKey)})

	return caCrtByte, caKeyByte, nil
}
// GenerateSelfSignedCACertAndKey generate an self-signed CA and Key
GenerateSelfSignedCACertAndKey generate an self-signed CA and Key
// GenerateSelfSignedCACertAndKey generate an self - signed CA and Key
func GenerateSelfSignedCACertAndKey(CN string) ([]byte, []byte, error) {
	caKey, err := rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		return nil, nil, err
	}
	now := time.Now()
	caCrt := x509.Certificate{
		SerialNumber: big.NewInt(rd.Int63()),
		Subject: pkix.Name{
			CommonName: CN,
		},
		NotBefore:             now.UTC(),
		NotAfter:              now.AddDate(10, 0, 0).UTC(),
		KeyUsage:              x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
		BasicConstraintsValid: true,
		IsCA:                  true,
	}
	caCrtBuf, err := x509.CreateCertificate(rand.Reader, &caCrt, &caCrt, caKey.Public(), caKey)
	if err != nil {
		return nil, nil, err
	}
	caCrtByte := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: caCrtBuf})
	caKeyByte := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(caKey)})
	return caCrtByte, caKeyByte, nil
}
func GenerateSelfSignedCACertAndKey ( CN string ) ( [ ] byte , [ ] byte , error ) { caKey , err := rsa . GenerateKey ( rand . Reader , 2048 ) if err != nil { return nil , nil , err } now := time . Now ( ) caCrt := x509 . Certificate { SerialNumber : big . NewInt ( rd . Int63 ( ) ) , Subject : pkix . Name { CommonName : CN , } , NotBefore : now . UTC ( ) , NotAfter : now . AddDate ( 10 , 0 , 0 ) . UTC ( ) , KeyUsage : x509 . KeyUsageKeyEncipherment | x509 . KeyUsageDigitalSignature | x509 . KeyUsageCertSign , BasicConstraintsValid : true , IsCA : true , } caCrtBuf , err := x509 . CreateCertificate ( rand . Reader , & caCrt , & caCrt , caKey . Public ( ) , caKey ) if err != nil { return nil , nil , err } caCrtByte := pem . EncodeToMemory ( & pem . Block { Type : " " , Bytes : caCrtBuf } ) caKeyByte := pem . EncodeToMemory ( & pem . Block { Type : " " , Bytes : x509 . MarshalPKCS1PrivateKey ( caKey ) } ) return caCrtByte , caKeyByte , nil }
GenerateSelfSignedCACertAndKey generate an self-signed CA and Key
GenerateSelfSignedCACertAndKey generate an self - signed CA and Key