Washington - Apple CEO Tim Cook says his company will fight a federal magistrate's order to help the FBI hack into an encrypted iPhone belonging to one of the San Bernardino, California shooters. The company said that could potentially undermine encryption for millions of other users.Cook's response, posted early on Wednesday on the company's website, set the stage for a legal fight between the federal government and Silicon Valley with broad implications for conflicts over digital privacy and national security.US Magistrate Judge Sheri Pym had ordered Apple to help the FBI break into an iPhone belonging to Syed Farook, one of the shooters in the December 2 attack that killed 14 people. Farook and his wife, Tashfeen Malik, died in a gun battle with police.The ruling by Pym, a former federal prosecutor, requires Apple to supply software the FBI can load onto Farook's county-owned work iPhone to bypass a self-destruct feature that 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.The Obama administration has embraced stronger encryption as a way to keep consumers safe on the internet, but has struggled to find a compelling example to make its case.Cook said "this moment calls for public discussion, and we want our customers and people around the country to understand what is at stake". He argued that the order "has implications far beyond the legal case at hand". He said it could undermine encryption by using specialised software to create an essential back door akin 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."Federal prosecutors told Pym that they can't access Farook's work phone because they don't know his passcode and Apple has not co-operated. Under US 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.Apple has provided default encryption on its iPhones since 2014, allowing any device's contents to be accessed only by the user who knows the phone's passcode. Previously, the company could use an extraction tool that would physically plug into the phone and allow it to respond to search warrant requests from the government.The magistrate's order requires that the software Apple provides be programmed to work only on Farook's phone, and said Apple has five days to notify the court if it believes the ruling is unreasonably burdensome.It was not immediately clear what investigators believe they might find on Farook's work phone or why the information would not be available from third-party service providers, such as Google or Facebook, though investigators think the device may hold clues about whom the couple communicated with and where they may have traveled.The phone was running the newest version of Apple's iPhone operating system. It was configured to erase data after 10 consecutive unsuccessful unlocking attempts. The FBI said that feature appeared to be active on Farook's iPhone as of the last time he performed a backup.Farook and Malik took pains to physically destroy two personally owned cellphones, crushing them beyond the FBI's ability to recover information from them. They also removed a hard drive from their computer; it has not been found despite investigators diving for days for potential electronic evidence in a nearby lake.Farook was not carrying his work iPhone during the attack. It was discovered after a subsequent search.The judge didn't spell out her rationale in her three-page order, but the ruling comes amid a similar case in the US District Court for the Eastern District of New York.Investigators are still working to piece together a missing 18 minutes in Farook and Malik's timeline from that day. Investigators have concluded they were at least partly inspired by the Islamic State group; Malik's Facebook page included a note pledging allegiance to the group's leader around the time of the attack.