It took just a few hours for the Justice Dept. to gauge how its legal action against Apple would be perceived by the public.

Not long after a California court released an order compelling Apple to help the FBI unlock an iPhone used by one of the San Bernardino shooters, there was an outpouring of support in Apple's favor, and little compassion for the government's case.

Within hours of reading headlines with words like "backdoor," Apple responded to the growing public empathy with a letter on its website stating that the company will "oppose this order." Apple had made iOS 8, which debuted in September 2014, impossible for anyone other than the phone's owner to unlock -- including law enforcement and Apple itself.

But in the days running up to the judge signing the court order, the Justice Dept. had "stacked the deck" against the iPhone maker, according to a person with direct knowledge of the case.

It was a move to thrust the long-standing debate over encryption between tech companies and law enforcement into the public eye -- one that the government reportedly ended up regretting.

Over the weekend, a report in The New York Times highlighted the rift between some in government, who have begun to believe that the Justice Dept. may have "made a major strategic error by pushing the case into the public consciousness." According to the paper, senior officials said a public conflict "is exactly what [senior officials] have been trying to avoid," particularly given that some government departments have wanted tech firms to help fight propaganda laid out by the so-called Islamic State regime.

That conflict was blown wide open when the Justice Dept.'s motion to compel Apple's help was approved by a California judge -- a move that prosecutors pushed to make public.

Two sources speaking on the condition of anonymity said Apple had reached out to Justice Dept. prosecutors in Washington DC to ask for the motion to be filed under seal to prevent a circus-like media environment that Apple could not control. The iPhone maker is known for its carefully-crafted public message and works relentlessly to prevent its image from being tarnished. With the case already in the hands of local prosecutors, Justice Dept. officials in the capital said it was up to the US Attorney's Office in Los Angeles, Calif., which had jurisdiction.

When Apple reached out to the the US Attorney's Office in Los Angeles, prosecutors were already preparing to move ex-parte -- effectively pushing the case in front of a "friendly" judge, Sheri Pym, a former federal prosecutor for almost a decade, in order to get a swift resolution.

Pym issued the order without giving Apple a formal chance to respond.

With the Justice Dept. pushing for an unprecedented kind of order, the government was poised to launch a public relations campaign, said a source, in an effort to pull at the public heartstrings of those who suffered as a result of the shootings.

Given that it's a Californian judge fighting a case against a Californian company in a Californian court, miles away from San Bernardino where 14 people were killed in the worst terrorist attack suffered on US soil since the September 11 attacks, prosecutors wanted to make this local case affect an entire nation.

The Justice Dept. wanted to draw outrage, painting Apple as the criminal.

With a public relations battle about to explode in its hands, Apple knew it would have to alter its usual muted position and composed demeanor to counter the government's rhetoric.

Ready for a fight, Apple did not make the request for Los Angeles prosecutors to file the motion under seal.

Apple's bid to have the case filed under seal drew some private criticism, accusing Apple of trying to maintain its public image in the face of a case that, if lost, would likely have a devastating effect on its products, its revenue, and its public image.

But one person close to Apple argued that the company wanted to craft a more dignified path to resolve the case by proceeding through the courts in private, without dragging its executives -- who normally shy from the spotlight -- as well as its carefully-managed public perception through the mud.

Had the case proceeded under seal, neither Apple or the Justice Dept. would be able to guarantee that the case could be unsealed and made public.

Apple and the Justice Dept. declined to comment on the record. (If that changes, we will update the post.)