code: func PrivateKeyToEncryptedPEM(privateKey interface{}, pwd []byte) ([]byte, error) {
  	if privateKey == nil {
  		return nil, errors.New("Invalid private key. It must be different from nil.")
  	}
  
  	switch k := privateKey.(type) {
  	case *ecdsa.PrivateKey:
  		if k == nil {
  			return nil, errors.New("Invalid ecdsa private key. It must be different from nil.")
  		}
  		raw, err := x509.MarshalECPrivateKey(k)
  
  		if err != nil {
  			return nil, err
  		}
  
  		block, err := x509.EncryptPEMBlock(
  			rand.Reader,
  			"PRIVATE KEY",
  			raw,
  			pwd,
  			x509.PEMCipherAES256)
  
  		if err != nil {
  			return nil, err
  		}
  
  		return pem.EncodeToMemory(block), nil
  
  	default:
  		return nil, errors.New("Invalid key type. It must be *ecdsa.PrivateKey")
  	}
  }
docs: // PrivateKeyToEncryptedPEM converts a private key to an encrypted PEM