Yes you can paint a brick fireplace but not of course inside the firebox.
The first thing to realise is that once you paint it, you cannot un-paint it. The paint will be worked into the small holes in the brick and will not come back out.
First clean the brick as best you can, probably using TSP.
Latex paint will definitely not peel because of the heat from a fireplace, and the paint technicians tell us that oil paint will not peel either. However decorative spray paints, like speckle or marble paint should not be used on an active fireplace, it will peel.
Work the first coat well into all the gaps and holes in the brick and mortar. A good job on the first coat will make final coating easy. If you don't fill all the little holes, they will continue to cause bubbles and holes in the other coats of paint.