Privateers
There was another class of pirate - one that countries supported. These pirates supported by governments were called privateers. For example, Elizabeth I of England supported Sir Francis Drake so that he could attack the Spanish ships of the Spanish Main and share the treasure with her. At that time England was poor and needed all the money it could get, by whatever means.
England was not alone in this. The United States Constitution of 1787 authorised Congress to issue 'contracts' between the government and the privateer, so that this could be shown to any foreign navy. It meant that a privateer could not be charged with piracy while attacking the targets named in his commission. All countries abided by this, except the Spanish, who would execute foreign privateers with their letters of commission hung around their necks.
Privateers were actually a large proportion of the total military force at sea during the 17th and 18th centuries. During the American Revolution, about 55,000 American seamen served aboard the privateers, which had 1,700 ships. Throughout the American Civil War, Confederate privateers successfully attacked Union merchant ships.
As you will know from the news today, pirating is not a thing of the past, but continues today, especially in the China Sea and the Indian ocean off the coast of Africa.