There are three fonts of morality: (1) intention, (2) moral object, (3) circumstances.
In order to be moral, each and every knowingly chosen act must have three good fonts. If any one or more fonts is bad, the act is immoral. Every act with an evil moral object is intrinsically evil and always immoral, regardless of intention or circumstances.
If any one font is bad, the act is always a sin — as long as that font, or any other font, is bad. If all three fonts are good, the act is always moral; it is permissible without sin.
“The morality of each font is independent of the other fonts. A good intention cannot cause an evil moral object to become good. A good intention cannot cause evil consequences to become good. A good moral object cannot cause an evil intention to become good. A good moral object cannot cause evil consequences to become good. A good consequence cannot cause an evil intention to become good. A good consequence cannot cause an evil moral object to become good. All this is true because all that is evil before the eyes of God is certainly evil, and all that is good before the eyes of God is certainly good. Nothing can cause evil to become good, or good to become evil. For all the goodness in Creation is of God, who is eternal and unchanging Goodness, and all evil is opposed to God, who never does evil in the least. The absolute separation of good and evil is essential to every general principle of morality and to every particular application of morality. The rejection of this absolute separation thoroughly corrupts a proper understanding of moral truth. If good could become evil, or if evil could become good, then the moral law would have no force at all. If good could become evil, or if evil could become good, then God would not exist. For the Goodness of God is the same as His very Existence.”
quoted from my book: The Catechism of Catholic Ethics, n. 88