Yesodei HaTorah 5:9
If a man becomes so attracted to a woman that he becomes sick and is in danger of dying, and the doctors say that the only thing that can save him is to have intimate relations with this woman, he should be permitted to die, even if the woman is not married. He should not even be told to speak to this woman from behind a fence. This is so that Jewish women will not be objectified and treated as if they were cheap.
Yesodei HaTorah 5:10
If a person intentionally violates a Torah prohibition without being coerced, in order to mock or to spite God, he desecrates God’s Name. Regarding taking oaths in vain, Leviticus 19:12 says, “you are desecrating the Name of your God; I am Hashem.” If the person violates the commandment in front of ten Jews, he desecrates God’s Name publicly.
On the other hand, if a person refrains from committing a sin, or if he performs a mitzvah, with no ulterior motive, not from fear and not for honor but simply the sake of God as Joseph did when he held himself back from Potifar’s wife – such a person sanctifies God’s Name.