If you create a module the code of it will be available for people to copy/edit, you cant prevent this sadly, although you can make it harder.
In terms of adding a access key, make sure your validation is performed by api requests to your own server rather than in the module it self.
Then when it comes to protecting your module code you will need to encode/obscurify it. While this will not make it 100% safe it will make it much harder for people to edit. I would recommend only encoding critical parts of the module though, as each file its got to decode will affect performance. Make sure to encode your licencing logic though.
One of the most popular tools for encoding php code is https://www.ioncube.com/php_encoder.php .
Magento2 module activation license