Do the Ends Justify the Means?

Thomas Aquinas, on whether the ends justify the means:

On the contrary, Boethius says (De Differ. Topic. ii) that "if the end is good, the thing is good, and if the end be evil, the thing also is evil."

That is a simple way of stating it, but he elaborates:

Nothing hinders an action that is good in one of the way mentioned above, from lacking goodness in another way. And thus it may happen that an action which is good in its species or in its circumstances is ordained to an evil end, or vice versa. However, an action is not good simply, unless it is good in all those ways: since "evil results from any single defect, but good from the complete cause," as Dionysius says (Div. Nom. iv).