Finasteride and Dutasteride (Avodart) are medications which shrink the prostate, so it's a treatment for BPH, not prostate cancer. (They've been tried as hormone therapy treatments for prostate cancer, but that doesn't work.) Finasteride is perhaps more commonly used that Dutasteride. They prevent the conversion of Testosterone into the much more powerful androgen Dihydrotestosterone (DHT) which is what the prostate prefers to use. When starved of the DHT it prefers, it shrinks, taking about 6 months to reach its new reduced size. This can alleviate some symptoms of enlarged prostate.
Hair follicles are also sensitive to DHT, with it causing both body hair growth from puberty, and conversely male pattern balding, so these can be impacted to. It can also impact libido a bit (although you'll still have Testosterone) and that can impact erections a bit too. (Finasteride at a low dose is used as a medication to reverse baldness, but they probably won't work for this if you've been bald for many years.)
These will also halve your PSA level, but they don't have any impact on your prostate cancer risk, so you need to double up your PSA test results when you're on them, to assess prostate cancer risk.
There are 3 forms of DHT. Finasteride prevents one of these being produced, and Dutasteride prevents two of them being produced.