Restricting Content by License / Code
Take a look Commerce File &amp; its dependency Commerce License. These module enable a licensing product functionality tied to some sort of digital file. This will get you a good way there, but you'll probably add extra features for your particular use (e.g. some sort serial code validation before displaying the download link).