On the so-called dark web, drug dealing and other illicit sales have thrived in recent years, the authorities have said, through hidden websites like Silk Road and hard-to-trace digital currencies like Bitcoins.

On Monday, the government charged that in the shadows of an undercover investigation of Silk Road, a notorious black-market site, two federal agents sought to enrich themselves by exploiting the very secrecy that made the site so difficult for law enforcement officials to penetrate.

The agents, Carl Mark Force IV, who worked for the Drug Enforcement Administration, and Shaun W. Bridges, who worked for the Secret Service, had resigned amid growing scrutiny, and on Monday they were charged with money laundering and wire fraud. Mr. Force was also charged with theft of government property and conflict of interest.

A criminal complaint unsealed on Monday in federal court in San Francisco outlined the allegations against the two former agents.