Construction of invariant whiskered tori by a parameterization method. Part I: Maps and flows in finite dimensions