WASHINGTON -- The high-stakes legal fight between Apple Inc. and the Justice Department over a locked iPhone shifted Tuesday from the courts to the halls of Congress.

FBI Director James Comey and Apple chief lawyer Bruce Sewell appeared before the House Judiciary Committee for a hearing on encryption, security and privacy.

Comey, testifying first, acknowledged that a "mistake" was made in the handling of San Bernardino gunman Syed Rizwan Farook's iPhone in the 24 hours following the December attack.

Get Breaking News Delivered to Your Inbox

The FBI previously reported that investigators had reset Farook's iCloud account password. As a result, Comey said Monday, it became "impossible later to cause the phone to back up again to the iCloud." However, he maintained that even if the mistake hadn't been made, the FBI still would not have been able to get everything off the iPhone without Apple's assistance.

"Apple is very good at what it does. It's a wonderful company, it makes wonderful products. They have set out to design a phone that can't be opened. And they're darn near succeeding," Comey said. "That doesn't make them bad people, it just creates a challenge for us that we're not yet up to meeting without intervention from the courts."

Bruce Sewell, Apple's senior vice president and general counsel. Drew Angerer, Getty Images

When it was Sewell's turn to testify, he elaborated on the impact the iCloud reset may have had. "The way that we can backup these phones is we connect them to a known Wi-Fi source, a source that the phone has already connected to before and recognizes. ... It will, in certain circumstances, auto-backup. So the very information that the FBI is seeking would have been available and we could have pulled it down from the cloud," he said. "But by changing the password -- this is different than the [phone's] passcode -- by changing the password, it was no longer possible for that phone to auto-backup."

The hearing comes amid two significant and conflicting court rulings in New York and California on whether Apple can be forced to help the FBI gain access to locked iPhones.

In California, a judge has ordered Apple to create software to bypass the auto-erase security function on an iPhone used by Farook, who along with his wife Tafsheen Malik killed 14 people in one of the deadliest attacks on U.S. soil. In New York, the judge in an unrelated drug case ruled in favor of Apple on Monday, saying it cannot be required to help unlock a suspect's phone to assist in an investigation.

Comey told lawmakers that technological advancements have been accompanied by "new dangers" which can prevent law enforcement from collecting critical evidence in criminal and terrorism investigations.

FBI Director James Comey. Drew Angerer, Getty Images

"When changes in technology hinder law enforcement's ability to exercise investigative tools and follow critical leads, we may not be able to root out the child predators hiding in the shadows of the Internet, or find and arrest violent criminals who are targeting our neighborhoods. We may not be able to identify and stop terrorists who are using social media to recruit, plan, and execute an attack in our country. We may not be able to recover critical information from a device that belongs to a victim who cannot provide us with the password, especially when time is of the essence," Comey warned in his opening statement. "These are not just theoretical concerns."

In response to a question about the legal authority to hack into a locked iPhone, Comey said the Founding Fathers created a legal process that allows investigators to search suspects' homes, and the same process should apply in this case. "They wouldn't have imagined any ... device that couldn't be entered" with a court order, he said.

"We are a rule of law country. The FBI is not cracking into your phone or listening to your communications except under the rule of law and going to a judge," Comey stressed.

But Apple maintains that by asking it to weaken the security of its products, the FBI would set a dangerous precedent.

In his opening statement, Sewell, Apple's vice president and general counsel, asked: "Should the FBI be allowed to stop Apple, or any company, from offering the American people the safest and most secure product it can make? Should the FBI have the right to compel a company to produce a product it doesn't already make, to the FBI's exact specifications and for the FBI's use?"

He also reiterated the central argument Apple has made in court: "They are asking for a backdoor into the iPhone ... Building that software tool would not affect just one iPhone. It would weaken the security for all of them."

Sewell took issue with the accusation that Apple's position is motivated by its "business model and brand marketing strategy," as the government argued in court documents.

"This is not a marketing issue. We're doing this because we think protecting the security and privacy of hundreds of millions of iPhone users is the right thing to do," he stressed. "To say that it's a marketing ploy or that it's somehow about PR really diminishes what should be a very serious conversation."