MegaUpload founder Kim DotCom has the right to sue New Zealand's spy agency for illegal surveillance, a court ruled Thursday.

The New Zealand Court of Appeal rejected a request from the country's attorney general to exclude the Government Communications Security Bureau (GCSB) from DotCom's lawsuit. The GCSB collected intelligence on Dotcom ahead of the 2012 raid on his house to determine whether he posed any danger to the police who would later swoop in by helicopter to arrest him.

New Zealand law prohibits the GCSB from conducting surveillance on the country's citizens, but the agency was under the false impression that DotCom, who was born in Germany, was not yet a citizen. That revelation led New Zealand Prime Minister John Key to apologize to DotCom, saying he is "entitled to be protected from the law when it comes to the GCSB, and we failed to provide that appropriate protection for him."

Chief High Court judge Justice Helen Winkelmann ruled last year that DotCom had the right to sue the agency and police, a decision that was challenged by New Zealand's attorney general.

MegaUpload is a cloud-storage locker that DotCom claims was completely legitimate and protected by the Digital Millennium Copyright Act. U.S. officials, who are trying to extradite DotCom and six associates to face piracy and wire fraud charges, say he encouraged users to store pirated videos, music, software, and other media and then share them with others.

DotCom had been hoping to force the U.S. government to present all of its evidence against him before it could extradite him. However, the Court of Appeal ruled late last week that the U.S. government will not be required to turn over all of its evidence against DotCom in order to obtain his extradition. A summary of its case would suffice, the judges ruled.

The United States said MegaUpload cost Hollywood studios and other copyright owners $500 million. DotCom faces 20 years in prison if convicted of all the charges.