Hilchos Lashon Hara chapter 10, section 17
Someone did something wrong, and Reuven asked Shimon: "Who did it?" Even if Shimon realizes that Reuven suspects him, and even if he saw who did it himself, he should answer: "I did not do it" (without saying who did).
(The exceptions: a sin between man and his fellow, when the rules explained earlier in this chapter are kept; or a sin between man and Hashem, according to chapter 4, paragraphs 5, 7 and 8.)
Everything we wrote so far is the strict law. But a pious person should go beyond the letter of the law. He should not deny that he did it, if the one who asked could then find out who really did it, and that person would be shamed.
We find even more than this in Sanhedrin (11a): many tanna'im (sages of the Mishnah) took the blame on themselves so the one who did wrong would not become known. Similarly, Sefer Chassidim (22) writes: "If you are with a group, and someone in the group did something wrong and it is not known who, say: 'I did the wrong,' even though you did not."
This completes the first part of the sefer Chofetz Chaim.