Why is Tim Cook so angry at the government?

A federal magistrate-judge ruled Tuesday that Apple must help the FBI break into the phone of one of the San Bernardino shooters. The FBI was unable to figure out the shooter's passcode, which is the only way to get inside his iPhone.

Here's the problem: Apple doesn't hold the keys to the shooter's iPhone. The only way to break through an iPhone's encryption lock is with a passcode, which isn't stored on Apple's servers.

The FBI could try to guess the shooter's passcode, but if investigators guessed wrong 10 times, the shooter's iPhone would permanently erase all of the content stored inside.

So the judge said Apple had to provide "reasonable technical assistance" to help it unlock the phone, including developing a software tool that would let investigators guess a passcode as many times as it needed to in order to break into the phone.

In a public letter opposing the FBI's demands, Tim Cook didn't mince words.

"The government is asking Apple to hack our own users and undermine decades of security advancements that protect our customers," Cook said. "The same engineers who built strong encryption into the iPhone to protect our users would, ironically, be ordered to weaken those protections and make our users less safe."

Related: Tim Cook says Americans shouldn't have to choose between privacy and security

Cook said that to comply with the ruling, Apple will have to rewrite its iOS operating system. But once Apple gives special access to one person or group, it will have to give access to anyone.

Apple (AAPL) called the FBI's demands a "backdoor," which is a nasty term in the cybersecurity world.

If you leave a key under the mat -- no matter how well hidden -- it gives bad guys a potentially easy way in. Similarly, if the FBI can use a backdoor into your iPhone, hackers could too.

It might not sound like a big deal to be able to guess an iPhone passcode as many times as you'd like. There are 10,000 possible four-digit PINs.

But hackers have access to incredibly powerful computer networks called botnets, which would allow them to guess nine passwords per second, according to Dino Dai Zovi, an independent security consultant and notorious Apple hacker.

If Apple allowed that kind of "brute force" attack on an iPhone, it would take hackers 18 minutes at most to guess an iPhone's password.

Related: Congress puts terrorism and tech in the spotlight

The debate over iPhone encryption started in September 2014, when Apple released iOS 8. That was the first operating system to encrypt iPhones by default, giving customers the only means of decrypting their phones. That means the only way for police to retrieve a suspect's photos, messages, email, contacts, call history, iTunes content, notes and reminders is with a passcode.

The FBI has been up in arms about Apple's encryption tactics, arguing that it will impede its investigations. It has been pleading with Congress to pass a law requiring Apple to build backdoors into its system. The FBI's demands have met stiff resistance, and the Obama administration said it would no longer pursue a legal strategy to combat Apple's encryption.

But the judge's order could shift the tide against Apple.

"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," Cook said. "And ultimately, we fear that this demand would undermine the very freedoms and liberty our government is meant to protect."