A Whitehat, also rendered as White hat or White-hat, is, in the realm of Information technology, a name that describes a person who is ethically opposed to the abuse of Computer systems. Realizing that the Internet now represents human voices from all around the world makes the defense of its integrity an important pastime for many. A Whitehat generally focuses on securing IT Systems whereas a Blackhat (the opposite) would like to break into them, but this is a simplification. A Blackhat will wish to secure their own machine and a Whitehat might need to break into a Blackhat's machine in the course of an investigation. Therefore the definition of and difference between Whitehat and Blackhat does have to take on some element of comparing good and bad, which is very subjective. Generally, someone with the Good of Society in Mind is a Whitehat, where someone without that in mind is a Blackhat.
Attacking corporate businesses that use unethical practices could be regarded as highly ethical and yet would normally be tagged with the title of Blackhat activity. However to them and others it may not appear bad even though it is against that local law. This type of Blackhat might be more accurately known as an Ethical Hacker. The definition of Hacker is another subject best answered by Eric Raymond. Also the Electronic Frontier Foundation, the GNU Project and Richard Stallman have strong ethical beliefs that might not fit comfortably into the category of blackhat or whitehat as they are in some ways acting against the interests of many closed source software businesses, and instead are in favour of open source and the wider public interest. These people are generally regarded as Hackers, which is certainly not a Blackhat in this definition. This ambiguity has caused the name Gray hat to be made, to try to cover ambiguous areas.
"Black and White" has many connotations related to race and religion throughout the ages and it is recognized that the terminology is not particularly useful, is possibly racist (implying that Whites are good and Blacks are Bad), and is in need of update.
The reference to colored hats comes from Hollywood’s use of hats in old black-and-white Westernmovies to help an audience differentiate between the good guys (white hats) and the bad guys (black hats).