The universal knowledge of Christ is then described: for he knew not only those who were on close terms with him, but strangers too. And therefore he says, for he knew all men; and this by the power of his divinity: "The eyes of the Lord are far brighter than the sun" (Sir 23:28). Now a man, although he may know other people, cannot have a sure knowledge of them, because he sees only what appears; consequently, he must rely on the testimony of others. But Christ knows with the greatest certainty, because he beholds the heart; and so he did not need anyone to give him testimony about men. In fa...ct, he is the one who gives testimony: "Look, my witness is in heaven" (Jb 16:20).
His knowledge was perfect, because it extended not only to what was exterior, but even to the interior; thus he says, He was well aware of what was in man's heart, i.e., the secrets of the heart: "Hell and destruction are open to the Lord: how much more the hearts of the children of men" (Prv 15:11).
Source: Commentary on John