The cosmic ray energy spectrum is calculated assuming that cosmic rays are generated by astrophysical objects provided by magnetospheres with a dipole magnetic field. With simple geometric considerations, the energy spectrum E-2.5 is obtained, independently on the particle species.