The National Security Agency hacked North Korea long before Sony Pictures Entertainment was hacked by a group backed by North Korea in November. The evidence gathered during the program helped the U.S. government tie Pyongyang to the attack on the Hollywood studio.

Former officials told the New York Times that the NSA began trying to hack into North Korea’s networks in 2010 by breaking into the Chinese networks that link North Korea to the rest of the world. The agency also sifted through links in Malaysia that hackers use and eventually hacked directly into Pyongyang with help from South Korea and other allies.

The NSA program included placing malware into North KOrea networks and computers that their hackers use.

Despite the program, NBC News was told that U.S. intelligence did not have a hint that Sony was a target until Nov. 24, when Sony told the FBI about the attack. Still, these efforts gave the government enough confidence to blame North Korea for the attack in December. President Obama then approved new economic sanctions against North Korea in response.

When NSA director Gen. James Clapper went to North Korea on Nov. 6 to secure the release of two Americans held in North Korea, he actually had dinner in Pyongyang with his counterpart there. However, officials told the Times that he did not mention the Sony attack at that point. An NSA spokesman told the Times that Clapper did not talk about “other matters” because of the “sensitivities surrounding the effort” to secure the Americans’ release.

image of President Barack Obama courtesy of Kristin Callahan/ACE/INFphoto.com