Apple CEO Tim Cook released a statement arguing against the FBI's recent order to hack into the San Bernardino shooter's iPhone 5c. See why he and Apple are refusing to do so. (Jhaan Elker/The Washington Post)

Apple CEO Tim Cook released a statement arguing against the FBI's recent order to hack into the San Bernardino shooter's iPhone 5c. See why he and Apple are refusing to do so. (Jhaan Elker/The Washington Post)

The Justice Department calculated that it held a winning hand — the passcode-locked Apple iPhone of a terrorist — when it went to a federal court in Riverside, Calif.

Not only did the agency want Apple to build special software to help the FBI crack open the phone, but the government also knew the order would be made public.

After a mass killing that provoked national outrage, the government hoped to win support far outside the courtroom in its bid to gain access to encrypted phones in criminal and terrorism cases.

“They picked this case to increase the chances of getting public opinion on their side,” said a former federal prosecutor.

Now, a single iPhone has reignited a broad debate about government surveillance and the needs of law enforcement vs. the need for privacy. The showdown escalated Friday with the Justice Department accusing Apple of putting its “brand marketing” ahead of the law. The stakes have soared, well beyond the fate of any particular iPhone.

“How can anyone back down now?” asked Mike McNerney, a former cybersecurity adviser to the secretary of defense and now a Truman National Security Project fellow. “You can’t solve [this case] when it’s the director of the FBI vs. the CEO of Apple.”

For more than a year, Apple and its chief executive, Tim Cook, have signaled in public comments that the company no longer wants a hand in exposing data stored on its devices. That became particularly evident in October, when Apple declined to help authorities crack an iPhone in a routine drug case.

The refusal was a clear break from Apple’s long history of complying without much objection, beginning with a government request in 2008 to extract data from the iPhone of a defendant accused of drugging and sexually abusing children. Since then, Apple has complied in about 70 other criminal cases.

But in classic Silicon Valley fashion, Apple sought a technological cure to its growing frustration with these requests. It wrote software, which debuted in late 2014, that it says makes it impossible for even the company to crack its newer devices.

Leading Apple’s charge is Cook, 55, who frequently talks about issues — from his support for gay rights to his objections to discriminatory “religious freedom laws” — with a passion more familiar to activists than corporate chieftains. Along the way, it has become increasingly clear that he values privacy in the same fundamental vein, some observers say.

“The very public stance, where we are today, that’s Tim Cook. This is his social activism,” said Rich Mogull, a longtime security analyst with Securosis.

Late Tuesday, Cook released a public letter responding to the initial order in the San Bernardino case, calling it “a dangerous precedent” and “an overreach by the U.S. government.” He argued that the government wanted Apple to create a security back door, a term recalling Edward Snowden’s revelations about National Security Agency snooping.

Cook was taking his case to the public, just as the Justice Department had.

A firestorm followed, with politicians, advocates and consumers instantly reacting to the resurrected fight between Silicon Valley and the government. Both Cook and FBI Director James B. Comey have been invited to testify about the battle before the House Energy and Commerce Committee.

On Friday, the government argued that Cook’s open letter was “publicly repudiating” the order. There was no waiting around for Apple to respond formally in court. Justice Department lawyers accused the company of designing and marketing a phone that allows technology, rather than the law, to control access to data.

Apple’s refusal “appears to be based on its concern for its business model and public brand marketing strategy,” the Justice Department wrote.

For the government, this is a case that puts the stakes in stark relief. It’s a terrorism case that left 14 dead. The phone might contain key data. “Authorities have vowed to the families they will leave no stone unturned,” said a law enforcement official, who spoke on the condition of anonymity because the investigation is ongoing. “And this is a pretty big rock.”

The position Apple staked out was long in the making.

Mogull, the analyst, recalled detecting Apple’s new emphasis on privacy at a Apple developers conference in June 2014. What caught his eye was that privacy tools had trickled down to minor items such as Apple’s health app. It seemed as if privacy was the focus in the computer giant’s trenches.

Mogull noticed again three months later when Apple updated its privacy policy — usually home to boilerplate legalese — to include a personal letter from Cook. It opened with: “At Apple, your trust means everything to us.”

“When have you ever seen a privacy policy like this from a company?” Mogull asked.

That was soon followed by Apple’s introduction of a new mobile operating system, iOS 8, an encrypted program that Apple says makes it impossible for the company to unlock a phone without a customer’s passcode. The iPhone of San Bernardino shooter Syed Rizwan Farook ran an even newer version, iOS 9.

Cook has never shied from trumpeting Apple’s focus on privacy, not drawing a distinction between the prying eyes of hackers and those of government officials.

Last February, he took the stage at a White House-organized event at Stanford University aimed at fostering cooperation between industry and the government on cybersecurity. President Obama was in the crowd. Cook’s brief speech made clear that he took his mission to heart.

“If those of us in positions of responsibility fail to do everything in our power to protect the right of privacy, we risk something far more valuable than money — we risk our way of life,” Cook said.

Months before the San Bernardino iPhone case, Apple was embroiled in a fight over access to another iPhone.

Law enforcement officials had seized the phone of a New York man named Jun Feng, who allegedly had distributed crystal meth. But the FBI and the Drug Enforcement Administration couldn’t extract its data, despite the phone running older, less-secure software, iOS 7, which Apple had the technical capabilities to unlock.

In October, the agencies turned to the company for help, following a protocol outlined by Apple. There were no signs of resistance from the company. A “data extraction expert” at Apple said the process could take two weeks, according to the government.

But days later, Apple balked. A company attorney told a judge that complying would be burdensome and could “tarnish the Apple brand.”

The Justice Department was clearly stunned.

“Now, this was a textbook example of Apple’s long-standing and responsible corporate practice of bypassing locked cellphones when it has a court order requiring it to do so,” Assistant U.S. Attorney Saritha Komatireddy argued in a federal courtroom in Brooklyn on Oct. 26. She pointed out that Apple had complied with 70 similar court orders since 2008, including cases involving child pornography and drugs.

Apple attorney Marc Zwillinger echoed the company’s hard line on privacy. “Never has the privacy and security of customer data been as important as it is now,” Zwillinger said.

He later added that Apple believes it is not in the business of accessing customers’ data and that “we shouldn’t be in that business, either on our own or being conscripted by law enforcement.”

Zwillinger foreshadowed the battle over the terrorist’s iPhone, weeks before the San Bernardino shooting that left 14 dead.

He wondered aloud in court if the government’s requests would stop at unlocking a phone.

“Why wouldn’t the government say all the same things about modifying software?” he asked.

Requests for help accessing ­iPhones have usually involved more routine cases than terrorism incidents. For example, in 2014, prosecutors asked Apple to assist in unlocking a phone in a Baltimore case of food-stamp fraud.

Even those types of requests will become rarer as more iPhones are updated with the unhackable systems. Apple estimates that 90 percent of active iPhones now run that level of software, the kind that has caused so many problems in the San Bernardino case.

But the pursuit of airtight technology also brings unintended costs, such as with the iPhone belonging to Alison Parker, the TV news reporter in Roanoke, Va., who was fatally shot, along with cameraman Adam Ward, during a live broadcast in August.

The FBI and state police struggled for weeks to access her passcode-locked iPhone, recalled her fiance, Chris Hurst. Authorities wanted to know if she had had earlier contact with the shooter. Hurst just wanted to retain her photos and messages.

“It was frustrating,” Hurst said.

He eventually got almost all of her phone’s data, because she had backed it up to a remote server.