I've also thought of a variation on this, where the gun could have an embedded chip that acted as the decryption key. It would be physically embedded in such a way that you couldn't extract the chip without destroying it. You'd have a physical reader which would extract a time-sensitive code from the chip, which would unlock the file. This is more complex than a simple etched number key, but would have the advantage of making it impossible for anyone to retain the key illegally, without physically having the gun. Even if someone illegally kept a record of the key used to encrypt the file, it would only be useful at that moment. If someone later wanted to decrypt the file, he'd need a new key, and only the chip physically embedded in the gun could produce it.
It's a fascinating mathematical problem, when you think of the challenge this way.
Another idea, to get around the problem of crooks filing off the serials of a gun (or breaking the chip) to make in untraceable, would be to embed the number inside the metal with something like X-Ray lasers. I'd need to do research to see if this is feasible, metallurgically, but the idea would be to use an array of beams, focused beneath the surface of a core piece of the gun's metal, to create an isolated chemical change in the metal there, to write out the serial number. Then, the serial number could be read, even if surface numbers had been filed off, by using X-rays or the like to image the gun and show that subsurface variation. A crook would have to file to the point of destroying the weapon to rid it of the hidden code or codes.