WASHINGTON — In their years together as top national security officials, Michael Hayden and Michael Chertoff were fierce advocates of using the government’s spying powers to pry into sensitive intelligence data.

Hayden directed a secret domestic eavesdropping program at the National Security Agency that captured billions of phone records after the attacks of Sept. 11, 2001. Chertoff pushed for additional wiretapping and surveillance powers from Congress both as a top prosecutor and as Homeland Security secretary.

But today, their jobs have changed, and so, apparently, have their views on privacy. Both former officials now work with technology companies like Apple at a corporate consulting firm that Chertoff founded, and both are now backing Apple — and not the FBI, with which they once worked — in its fight to keep its iPhones encrypted and private.

They are among more than a half-dozen prominent former national security officials who, to varying degrees, have supported Apple and the idea of impenetrable “end-to-end encryption” during a furious national debate over the balance between privacy and security in the digital age.

In white papers, op-ed articles, conferences, newspaper and television interviews and elsewhere, the former officials have made their support for Apple clear. While their former jobs in the government are always featured prominently in their public appearances, their current business affiliations often go unmentioned.

The barrage of support has given Apple a public relations boost in a fight it once seemed destined to lose, but it has surprised and angered some law enforcement officials.

These officials question whether the business relationships that some of the former officials now have with Apple and other Silicon Valley companies — jobs that usually pay far above their former government salaries — are behind their enthusiastic advocacy of privacy and encryption.

Among those who have voiced support for Apple’s position are Mike McConnell, a former director of national intelligence; David Petraeus, a former director of the CIA; R. James Woolsey, another former CIA director; and Richard Clarke, a former top White House counterterrorism official. Like Chertoff and Hayden, they all now work with firms that have ties to the technology sector, records show.

It is unclear how much money Apple and other technology firms involved in the FBI litigation have paid to the firms where the former officials now work; most of the firms declined to discuss their private business dealings, calling them irrelevant.

McConnell, who served as national intelligence director under President Barack Obama and George W. Bush, argues that keeping the United States’ computer systems safe from rival nations and rogue hackers should outweigh the FBI’s interests in unlocking smartphones in criminal cases.

“I believe ubiquitous encryption is something that the nation is going to have to embrace,” McConnell, who is now a senior executive adviser at the consulting giant Booz Allen Hamilton, said in a telephone interview. “Apple has been leading the fight to go down that path, Google is right behind and Microsoft will be there before too long.”

Booz Allen’s executive vice president, Thad W. Allen, a former Coast Guard commandant, has also voiced support for Apple’s position on encryption, because, he said, U.S. technology firms need to stay competitive in the international market.

Booz Allen has made a recent push to form “strategic alliances” with Apple and other technology companies, executives said.

McConnell and other former national security officials said their work in the private sector had no impact on their public support for Apple. Not everyone agrees.

“They’ve followed the money and adopted pro-privacy positions that they wouldn’t have dreamed of taking while in government,” said Tim Shorrock, a writer and foreign policy commentator who wrote a book on the business side of intelligence.

Some current law enforcement officials say they have been angered by the former officials’ sharp and sometimes personal criticism of the FBI. (Hayden, for instance, said in an interview, “I think Jim Comey’s wrong,” referring to the bureau’s director.)

The Justice Department and the FBI declined to comment. But Stewart Baker, a former Homeland Security official who is one of the few former officials publicly backing the FBI in the encryption debate, said it was frustrating to see old colleagues now echoing what he sees as erroneous assertions from Apple about the threat to its customers’ privacy.

Still, he conceded that the efforts had been effective. What started as a dispute over a locked iPhone used by a terrorist in San Bernardino, California, has instead become a broader one over privacy and computer security, Baker said, and “they’re getting a lot of people to side with Apple.”

So strong is their support that Apple has included comments from several of the former officials in its legal pleadings. One filing included a comment from Chertoff at a conference last month that if Apple were forced to create a “back door” to get around its encryption, it would be like creating “a bacteriological weapon.”

Another vote of support that Apple has included in its legal filings came from Hayden, who is one of the top executives at Chertoff’s consulting firm, the Chertoff Group. “America is more secure — America is more safe — with unbreakable end-to-end encryption,” Hayden, who led both the National Security Agency and the CIA, told a television interviewer a week after the Apple fight broke out.

Chertoff’s firm also produced a 28-page report this year on the value of encryption, and its dealings with technology companies on security issues are extensive. Apple was also a corporate sponsor of a cybersecurity conference it hosted in October.

Hayden has acknowledged that he might have come down differently in the Apple dispute when he was the head of the NSA. If faced with an unbreakable device, he might have gone straight to the budget office and said, “I’m going to need another $500 million because I’m going to kick my way in,” he told the American Enterprise Institute, a conservative think tank.

Still, Hayden said in a telephone interview that his strong stance on encryption dated back years and was not influenced by his post-government work at the Chertoff Group.

“It doesn’t have any relevance to what I think about this,” he said. “I answered this on its merits.”

Chertoff was traveling and unavailable for comment, the Chertoff Group said. The firm declined to discuss its financial dealings with Apple.

But Chertoff acknowledged in a panel discussion last month that during his time inside the government, there were situations in which “I knew I had to move heaven and earth” to find out where a threat was coming from. His current focus on encryption, he said, is complementary to that previous stance on security and not contradictory.

The encryption debate erupted in February after the FBI said it needed Apple’s technical help to get into the iPhone used by Syed Rizwan Farook, one of the San Bernardino attackers.

Initially, the FBI appeared poised to win the battle for public opinion. The attack, which killed 14 people, was the worst terrorist strike on U.S. soil since the Sept. 11 attacks. Farook was dead; the phone’s owner — the county of San Bernardino, where he worked — had consented to the search; and the Justice Department had a court order to do it.

But Apple has since gained public sympathy, with polls giving it a small but growing edge over the FBI in support, and the battle has essentially ended in a draw now that the FBI has managed to get into the phone by paying an outside group to help hack it.

With the FBI still pushing to open other locked phones, Apple’s backers are preparing for a long fight.

Hayden, the former NSA director, warned listeners last month at the American Enterprise Institute that the flare-up in the San Bernardino case was “not a one-and-done.”

Encryption is at the root of Internet communications, Hayden said, and “there is nothing we can do to stop that.” His advice to his onetime government colleagues on the other side of the fight was simple: “Get over it,” he said.