This article is from the Hiking/Backpacking With Canines, by Terri Watson with numerous contributions by others.
Not all dog owners are responsible with respect to their pets behavior
on the trail. Some will even allow aggressive dogs off-leash.
Encounters with these dogs can result in a fight between your animal
and theirs, even if your dog is leashed, so be prepared to prevent
this occurance. Although I've personally not had a problem yet, a
fellow hiker who has repeatedly run into this scenario offers the
following advice: Always carry a can of Halt!, which is a mild
pepper-spray, the exact same stuff many local letter-carriers have on
their belts. It can be bought for around $6.00 in many cycling stores,
and is legal and definitely works. He points out that while he hates
to hurt the dogs (the owners are the ones that really need the
correction), his and his dogs' safety comes first, plus, it's more
humane to stop a fight before it starts. The stuff has no lasting
effects and can be washed out of the dog's eyes or whatever with
water. Halt! has a range of only some 15' or so, and if there's a wind
blowing, you or your dog can get a "back-blast" from it if you're not
careful. He always makes every effort to resolve the issue in other
ways but if he thinks an attack is coming (you learn to read their
body-language after awhile), he uses it and just keeps going.