RELATED: How Apple's security features have locked investigators out
This sets up an extraordinary legal fight with implications for consumers, as well as digital privacy. There's been a lot of talk about privacy versus security, but the outcome of this case could have an impact on people all across the globe.
Cook's ferocious response, posted early Wednesday on the company's website, came after an order from U.S. Magistrate Judge Sheri Pym that Apple Inc. help the Obama administration break into an encrypted iPhone belonging to one of the shooters in the December attack.
Cook released a statement saying: "While we believe the FBI's intentions are good, it would be wrong for the government to force us to build a backdoor into our products. And ultimately, we fear that this demand would undermine the very freedoms and liberty our government is meant to protect."
The government said it needs Apple's expertise to create a way to get past the default encryption setting that requires a passcode only the user knows.
Tech analyst Tim Bajarin said creating that software is problematic. "As soon as Apple creates a back door, the phone become vulnerable. It doesn't matter and hackers are so brilliant these days that even if they got a whiff of how it was done, they'll find out how to do it," he said.
RELATED: Apple argues encryption backdoor would create slippery slope
Some digital rights advocates said it would be an invasion of privacy. "We deserve tools that make us safe, and we can't undermine the security on the off chance that in the future, one of us might become a bad guy," Electronic Frontier Foundation spokesperson Cindy Cohn said.
Former Swedish Prime Minister Carl Bildt is chairman of the Global Commission on Internet Governance. He was at Stanford discussing cybersecurity, and shared some of his concerns. "We'll have the Chinese, we'll have the Russians, we'll have the Iranians, we'll have the Saudis asking for the same sort of access, and the same sort of backdoors in more or less similar cases," he said.
The FBI director told congress last week, encryption is a major problem for law enforcement who find a device that can't be opened even when a judge says there's probable cause.
Cook said this moment calls for a public discussion and wants Apple's customers and people around the country to understand what is at stake. "I'm not hiding anything, but I feel like it's a violation of privacy," Cupertino resident Kristen Dreher said.
"I guess I see it both ways where Apple's going to be tight on what they created not wanting a back door. But the other way is, hey it's the FBI and if it's going to help out our government and safety then I'm all for it," San Jose resident Riley Thorning said.
The first-of-its-kind ruling was a significant victory for the Justice Department in a technology policy debate that pits digital privacy against national security interests.
Pym's order to Apple to help the FBI hack into an encrypted iPhone belonging Farook set the stage for a legal fight between the federal government and Silicon Valley. The ruling by Pym, a former federal prosecutor, requires Apple to supply highly specialized software the FBI can load onto the county-owned work iPhone to bypass a self-destruct feature, which erases the phone's data after too many unsuccessful attempts to unlock it. The FBI wants to be able to try different combinations in rapid sequence until it finds the right one.
RELATED: Apple slams judge's order to unlock shooter's iPhone
Federal prosecutors told the judge in a court application that they can't access a work phone used by Farook because they don't know his passcode and Apple has not cooperated. Under U.S. law, a work phone is generally the property of a person's employer. The magistrate judge told Apple in Tuesday's proceeding to provide an estimate of its cost to comply with her order, suggesting that the government will be expected to pay for the work.
In his website posting, Cook said the U.S. government order would undermine encryption by using specialized software to create an essential back door that he compared to a "master key, capable of opening hundreds of millions of locks."
"In the wrong hands, this software - which does not exist today - would have the potential to unlock any iPhone in someone's physical possession," Cook wrote. "The FBI may use different words to describe this tool, but make no mistake: Building a version of iOS that bypasses security in this way would undeniably create a back door. And while the government may argue that its use would be limited to this case, there is no way to guarantee such control."
Apple will likely file an appeal with the court sometime this week.
Digital rights groups are holding rallies at Apple stores in the Bay Area and across the country.
Click here for full coverage of the San Bernardino mass shooting.
The Associated Press contributed to this story.