An iPhone. (Carolyn Kaster/AP)

Apple filed a motion Thursday opposing a federal order that would force the company to help the Justice Department access an iPhone used by one of the San Bernardino attackers, the latest step in a legal battle that could stretch out for months.

The filing comes as the two sides are engaging in a public back-and-forth that, in the coming weeks, will extend to an appearance before Congress and a court hearing. While the debate centers on a locked iPhone 5C, it has far-reaching consequences about the way a digital society balances privacy and civil liberties with law enforcement.

“This is not a case about one isolated iPhone,” Apple wrote in its motion, filed in the U.S. District Court for the Central District of California. “Rather, this case is about the Department of Justice and the FBI seeking through the courts a dangerous power that Congress and the American people have withheld: the ability to force companies like Apple to undermine the basic security and privacy interests of hundreds of millions of individuals around the globe.”

The company argues that the government is seeking to cut off a debate about the privacy issues in this case and that asking Apple to create a back door would expose personal information “to hackers, identity thieves, hostile foreign agents, and unwarranted government surveillance.”

The order last week from a magistrate judge in Riverside, Calif., did not ask Apple to break the phone’s encryption but rather to disable the feature that wipes the data on the phone after 10 incorrect tries at entering a password. That way, the government can try to crack the password using “brute force” — attempting tens of millions of combinations without risking the deletion of the data.

The FBI has insisted that it is not asking for a backdoor or a master key, and instead argued that its requests here are narrow and limited to this case. But Apple has publicly pushed back on that in recent days, with Tim Cook, the company’s chief executive, saying that it “would be bad for America” if the tech giant complied with the government.

The tech giant and federal authorities are girding up for a months-long battle that could eventually wind up at the Supreme Court. Legal analysts are divided on who has the stronger case, though most industry officials agree that the outcome could have deep implications for how far the government can go to force them to comply with demands to give it access to unencrypted data.

While the Justice Department has argued that it only wants help with an investigation that it says could lead to other terrorists, Apple has resisted and said this case creates a dangerous precedent. In its motion Thursday, Apple said that the government’s claims of this being a narrow request are untrue, arguing that if it acceded here, it would undo the security of its devices and expose its customers to vulnerabilities.

“In short, the government wants to compel Apple to create a crippled and insecure product,” Apple wrote in the filing. “Once the process is created, it provides an avenue for criminals and foreign agents to access millions of iPhones.”

The Justice Department forced the issue into the courts when it got a California judge last week to issue an order — unprecedented, Apple says — demanding that the firm build new software to help the FBI unlock an iPhone used by one of the two attackers who killed 14 people and injured 22 others in the Dec. 2 attack in San Bernardino.

FBI Director James Comey testifying before a House committee on Thursday. (Jim Lo Scalzo/EPA)

“This is the hardest question I have seen in government,” FBI Director James Comey said Thursday. No matter the court outcome, he said, the broader policy question is one that the people and Congress should decide.

“It’s really about who do we want to be as a country and how do we want to govern ourselves,” Comey told the House Intelligence Committee.

Comey had posted a public letter earlier this week saying that the iPhone used by one of the San Bernardino shooters could possibly contain information about other terrorists. On Thursday, though, Apple pointed to Comey’s letter and said the government has offered “nothing more than speculation” about what the iPhone could produce.

Cook’s scathing objection to the order — and his vow to fight it in court — overnight transformed what had been a simmering disagreement between the tech industry and the government into a high-stakes showdown.

Apple’s motion is its first response in court to last week’s order, but a flood of other filings are expected. Tech companies are rushing to file briefs by next week in support of Apple. Families of victims will do the same on behalf of the government.

“Simply put, the government’s request is entirely unprecedented and its legal theory dangerous,” said Alex Abdo, a staff attorney with the American Civil Liberties Union, which is writing a friend-of-the-court brief for Apple. “I think courts will recognize that if Congress wanted the government to have this sweeping authority, then it would have said so.”

Law enforcement officials, though, have pushed back on the suggestion that Apple’s actions are virtuous. Cyrus R. Vance Jr., the Manhattan district attorney, and William J. Bratton, the New York City police commissioner, released a statement last week saying that Apple’s refusal to comply with the FBI is proof of how tech companies “are thwarting serious criminal investigations and impeding public safety.”

The firm and its tech industry supporters are seeking to cast the issue as sweeping, with “chilling” implications. But the government is striving to paint the issue as narrowly as possible, stressing it is asking for a software modification to apply to only one phone, which was used by one of the attackers, Syed Rizwan Farook. Farook was killed in a shootout with police hours after the attack. His phone, which was given to him in his job at the county health department, has remained inaccessible since it was recovered by authorities, though the FBI accessed some data that was backed up to iCloud weeks and months before the attack.

In its motion Thursday, Apple again criticized the FBI for having Farook’s iCloud password changed after the attack, writing that if agents had checked with the tech company before they “inadvertently foreclosed a ready avenue,” the current court fight might have been averted.

Oral arguments in this case are scheduled for March 22 in Riverside, Calif. Apple has enlisted high-powered Republican attorney Ted Olson, a former solicitor general. When contacted about when he joined the case, Olson referred questions to Apple.

Apple Chief Executive Tim Cook. (Richard Drew/AP)

Apple has also begun working on security enhancements that would make it impossible for the company to unlock newer iPhones in the manner being sought in this case.

Even as the legal battle on the West Coast is commencing, a separate but related case in New York turns on a key legal issue at the heart of the California showdown. That case involves a drug dealer’s phone that runs on an older operating system, of the sort that Apple has bypassed at least 70 times in the past to extract data for federal authorities.

Nonetheless, in both cases, the government is relying on the All Writs Act, a 1789 law that authorizes the courts to “issue all writs necessary or appropriate in aid of their respective jurisdictions.”

In its motion Thursday, Apple argued that the 1789 All Writs Act does not permit the court to issue the order. The law, the firm’s attorneys argued, is intended to enable the courts to “fill in gaps in the law” but does not grant them “free-wheeling authority to change the substantive law, resolve policy disputes or exercise new powers that Congress has not afforded them.” Simply put, the firm says that Congress has never authorized judges to compel third parties to provide decryption services to the FBI. And the colonial era law does not permit the courts to compel such a service where Congress has chosen not to act.

The Justice Department has argued in both cases that the act empowers the courts to require companies to provide technical assistance to the government. In Brooklyn, that means extracting encrypted data from phones that authorities cannot get on their own. In California, the government wants Apple to do something it has never done before: build software to override a security feature on a newer operating system so that the FBI can try to crack the phone’s password.

The magistrate judge in Brooklyn, James Orenstein, has signaled he will side with Apple. In an opinion last fall, he said he does not believe All Writs Act applies in instances where Congress had the opportunity but failed to create an authority for the government to get such help.

Orenstein may issue his ruling soon. And though it will not be binding, and involves a different technical issue, it is likely to have outsize impact given the national attention focused on the San Bernardino case.