On 11 January 1863 Hatteras encountered the Confederate commerce raider CSS Alabama under Captain Raphael Semmes flying the British flag (an acceptable practice under the law of the sea at the time) and indicating that she was HMS Spitfire.
As a boarding party approached Alabama she broke out the Confederate ensign and commenced firing.*
It has never been either acceptable or legal for a Naval vessel to impersonate either a civilian vessel of another sovereign state or a naval vessel of a foreign sovereign state. Ever. The closest thing to it is to refuse to fly any colors when in international waters.