President Donald Trump speaks before signing an executive order on health care in the Roosevelt Room of the White House, Thursday, Oct. 12, 2017, in Washington. (AP Photo/Evan Vucci)

A former Louisiana private investigator accused of attempting to illegally obtain Donald Trump's tax returns before last year's U.S. presidential election cannot argue to a jury that he was merely trying to test a government website for security flaws, a federal judge ruled Thursday.

Jordan Hamlett, 32, of Lafayette, may, however, be allowed to testify that he had no intent to deceive, Senior U.S. District Judge James Brady said at the end of a short hearing in the case.

Brady's ruling prevents Hamlett from using a so-called "white hat" defense, or being allowed to argue he tried to access Trump's unreleased tax returns for a good and ethical reason.

Baton Rouge PI a 'white hat hacker,' sought Trump tax returns to test security flaw, attorney says

Hamlett is accused of trying to obtain Trump's tax returns in September 2016 through a U.S. Department of Education online student financial aid tool. He is charged with misrepresenting his Social Security number.

Federal prosecutors were objecting to Hamlett using any sort of "white hat" defense.

Assistant U.S. Attorney Ryan Rezaei argued to Brady on Thursday that Hamlett's desire to use such a defense is akin to an armed bank robber arguing he was simply trying to test a financial institution's security, or someone stealing a stereo system from a home with a security system sign in the yard and then telling police he was only trying to test the security system.

"What we have here is really a sentencing argument," Rezaei said of Hamlett's "white hat" argument, suggesting such an argument could be used to mitigate any punishment.

Feds move to block 'white hat' defense by Baton Rouge man in Trump tax return hacking case

Hamlett's attorney, Michael Fiser, argued to Brady that "intent to deceive" is a specific element of the crime Hamlett is accused of committing.

"The act itself is not completion of the offense," Fiser said. "The act is there. It's the intent that has to be proven."

Like Rezaei, Brady used an example to explain why Hamlett cannot use a "white hat" defense. If the judge were to access a secure government computer system that he had no permission to use and set off an intercontinental ballistic missile, he could not then argue, "I didn't intend to start World War III. I just wanted to test the system."

Brady assured Fiser that if the government does not prove the essential elements of the crime Hamlett is accused of committing, "This case won't go to the jury."

Hamlett's trial is set for Dec. 4. He faces up to five years in federal prison if found guilty.

Federal agents did not know at the time of their October 2016 interrogation of Hamlett at the Embassy Suites in Baton Rouge if he had succeeded in obtaining Trump's tax returns, according to a transcript of testimony from a federal court hearing in March, and they feared a public release of the financial documents could influence the presidential election that was less than two weeks away.

Federal judge refuses to toss PI's statements to agents in Trump tax return hacking probe

Follow Joe Gyan Jr. on Twitter, @JoeGyanJr.