How can I make files inaccessible to the user, but available to my program?
I'm making a small game right now and want users to be able to save their symbols, which will probably be stored in a text file. Is there a way to make this text file inaccessible to the user in windows explorer or whathaveyou so that saving unauthorized access is not possible (or at least harder) but also available to my program?
source to share
What you are asking is functionally impossible unless your game or daemon is running as another user that the player's account does not have access to. This is usually not the case, as the player probably has administrator access to their computer. There is really no way to completely protect a file from an experienced root / administrator user without an external service that I know will store the secret key.
Some steps you can take to make it difficult to modify the file: Save the file, then generate a checksum, md5, sha2, or use some other hash function for the hash file. Then save the hash in a separate file (or pin it at the end of the one you wrote).
When you read a file, you run what you are reading with the same hashing function, and make sure the hash matches the hash you saved with the file.
This can of course be hacked by a savvy user, but it's a pretty good way to keep people from messing with the game file.
source to share