What does it mean to be a good corporate citizen?

That’s one of the questions being tested as Apple and the federal government battle over whether Apple should help the Federal Bureau of Investigation unlock an iPhone to gain access to encrypted data that officials say is necessary for their investigation of the San Bernardino, Calif., shootings that killed 14 people.

Apple initially assisted the F.B.I., but is now fighting a government order directing it to create a new piece of software to open the phone, contending that its position is meant to protect the privacy of its customers.

Aside from the thicket of legal issues raised by the case, does Apple have a moral obligation to help the government learn more about the attack? Or does it have a moral obligation to protect its customers’ privacy? Or how about its shareholders? And which of these should take precedence?

Timothy D. Cook, Apple’s chief executive, has long spoken about running his company based on certain values. He has used his position to advocate gay rights, for example, and pushed the company to be more “green,” once going so far as to tell a shareholder who questioned the return on investment of taking such stances, “If you want me to do things only for R.O.I. reasons, you should get out of this stock.”