A former CIA officer betrayed the U.S. by giving a Chinese spy information about human assets and other top-secret information in exchange for $25,000, prosecutors say.

A jury heard opening statements Wednesday in the trial of Kevin Mallory, 60, of Leesburg, Va.

Mallory, a former self-employed consultant, had grown suspicious about a Chinese think tank’s job offer, defense attorney Geremy Kamens said. Mallory had reportedly told CIA about the job offer, but prosecutors viewed that as an attempt to cover his tracks.

Defense lawyers countered that their client is a loyal American who was merely stringing the Chinese along to try to get them to expose details of their own intelligence operation.

Mallory’s plan folded in April 2017 at Chicago's O'Hare International Airport during a flight back from Shanghai when customs agents found $16,500 in unreported cash, prosecutor Jennifer Gellie told jurors. Gellie said that encounter prompted Mallory to reach out to old CIA contacts to concoct a cover story.

Mallory agreed to be questioned in May 2017 about his contacts. Gellie said that that he was caught off guard during that interview when a Samsung phone given to him by the Chinese displayed text conversations between Mallory and the Chinese recruiter. Mallory had expected the phone's secure messaging features would keep the conversation hidden, Gellie said.

Your object is to gain information, and my object is to be paid.

— Kevin Mallory, former CIA officer

In one text message, Mallory wrote "your object is to gain information, and my object is to be paid."

Agents searched Mallory's home and found two small computer discs containing top-secret documents. Mallory had sent some of those documents to the Chinese recruiter using the Samsung phone, Gellie said.

"Kevin Mallory chose to pass closely held government secrets to a Chinese government agent," Gellie told the jury.

Kamens, though, said Mallory reached out to his old CIA contacts months before he was supposedly spooked by the airport inspection. The CIA contacts testified Wednesday that Mallory had contacted them in February 2017.

The trial is being heard in the Eastern District of Virginia, which is home to the CIA and Pentagon. Still, espionage trials are a rarity, given that both sides have strong incentives to reach plea deals. The government is concerned about exposing secrets, while defendants are worried about potentially stiff sentences.

If convicted, Mallory faces up to life in prison.

The Associated Press contributed to this report.