These are Sanskrit words given to us by Krishna in the Shri Bagavatam, which is a more philosophical companion volume to the more well known Bagavata Gita.
What is said in the Bagavatam, right in its last chapter, is that if anyone says Ha Ra Ye Na Ma Ha, even inadvertently, he or she will attain salvation. It does not say when. Maybe it has to be said just before death and be on your mind after death. That belief is found elsewhere in Hinduism ( see for example the writings of Gandhi) and Buddhism (see for example the Tibetan Book of the Dead). Or perhaps it can be said at anytime during your life, as is the case for Born Again Christianity.
Hara or Hare is another name of god in the family of Vishnu type gods in Hinduism. Krishna is one of these gods. It is said that Vishnu, Hara, Hare, Krishna, and several other names are all the same god. Shiva is another god and a number of names are associated with Shiva. The principal mantra of Shiva is "Om na ma shiva ya"
My understanding, not being a Sanskrit scholar, is that both
(god name) Ye Na Ma Ha, and
Om Na Ma (god name) Ya,
mean "I bow to the (god name) within me."
So the practice of such mantras is in the direction of not worshiping images, but rather worshiping our (higher?) selves as a part of god. This is consistent with us already being in the Buddha light as is said in the Lotus Sutra.
A powerful cleansing Buddhist mantra is similar.
It is used to cleanse each succeeding chrakra starting from the base of the spine-Aim. The succeeding chakras are denoted by the Sanskrit words: Vam, Ram, Yam, Ham, the last being the throat chakra.
So in Buddhist practice you say each of the following mantras, first slowly, and then speeding up to a frenzy, and then slowing again. The speed up process goes for 4-5 minutes, hold for about a minute, and then slow down for about a minute.
Om-Ram-Na-Ma-Ha Solar Plexus
This sequence is repeated twice more to pull in light and then stimulate Kundalini, substituting different sounds for Aim, etc., at each chakra. But it is considered very dangerous to do so unless well prepared. So I will not publish those sounds.