The covariant quantization of the electromagnetic field in the Lorentz gauge gives rise to longitudinal and scalar photons in addition to the usual transverse photons. It is shown here that the exchange of longitudinal and scalar photons can produce entanglement between two distant atoms or harmonic oscillators. The form of the entangled states produced in this way is very different from that obtained in the Coulomb gauge, where the longitudinal and scalar photons do not exist. A generalized gauge transformation is used to show that all physically observable effects are the same in the two gauges, despite the differences in the form of the entangled states. An approach of this kind may be useful for a covariant description of the dynamics of quantum information processing.