Even as Silicon Valley speaks out against the U.S. government’s surveillance methods, technology companies are turning a handsome profit by mining personal data and peering into people’s online habits.

The industry’s profit machine has become tarnished by revelations that the National Security Agency digs deep into the everyday lives of Web surfers.

As a result, companies including Apple, Facebook, Google, Microsoft and Yahoo are becoming more aggressive in their attempts to counter any perception that they voluntarily give the government access to users’ email and other sensitive information.

Microsoft’s general counsel Brad Smith said in a blogpost last week that the U.S. government’s online surveillance efforts “threaten to seriously undermine confidence in the security and privacy of online communications.”

“Indeed, government snooping potentially now constitutes an ‘advanced persistent threat,’ alongside sophisticated malware and cyber-attacks,” Mr. Smith wrote.

The industry’s latest salvo came Monday with the release of an open letter to President Barack Obama and the introduction of a new website calling for more stringent controls on electronic espionage.

“The entire tech industry has been implicated and is now facing a global backlash,” says Daniel Castro, a senior analyst for the Information Technology and Innovation Foundation, a Washington D.C. think tank.

As part of the industry’s crusade, companies are going to court and to the U.S. Congress in an effort to force the government to reveal details of its online investigations.

They believe data will show that, in the past five years, information turned over to the government under court order has affected a small fraction of the more than 1 billion people who use their products.

More In: Comment | Opinion