The nation's top intelligence official said Tuesday that he's not optimistic that an agreement the U.S. recently struck with China will effectively deter cyber threats emanating from the communist nation.

In a hack linked to China, the personal data of some 22 million current and former U.S. government employees, contractors, job applicants and relatives was stolen.

President Barack Obama said that when he met with Chinese President Xi Jinping last week, he told him that cyber threats from China have to stop. Obama and Xi agreed not to conduct or knowingly support cyber theft of trade secrets or competitive business information. The White House said the agreement covers cyber theft where the intent is to provide a competitive advantage to a country's companies or commercial sectors.

At a Senate hearing, Armed Services Committee Chairman John McCain asked Director of National Intelligence James Clapper if he was optimistic that the agreement would result in the elimination of cyberattacks from China.

Clapper replied: "No."

McCain, R-Ariz., said the Obama administration has not been aggressive enough in responding to cyberattacks or taking steps to effectively deter them.  "We are not winning the fight in cyberspace," he said. "The problem is a lack of deterrence."

Robert Work, deputy secretary of defense, agreed.

"I want to acknowledge upfront that the secretary and I recognize that we are not where we need to be in our deterrent posture," Work said. "We do believe there are some things the department is doing that are working, but we need to improve in this area without question."

Clapper said economic sanctions might be the best way to curb cyberattacks from China, which he said are "pretty pervasive."

"I think there is a question about the extent to which the (Chinese) government actually orchestrates all of it or not," he said.

Clapper added that when discussing penalties, policymakers also must remember that the U.S. conducts cyber spying too.

"We, too, practice cyber espionage and in a public forum, I'm not going to say how successful we are, but we're not bad," Clapper said. "I think it's a good idea to at least think about the old saw about people in glass houses should not throw rocks."