Encryption method with master key and user keys I am working on a concept for a game that in the end will allow data sharing via plain text, but I would like to give the user the option of encrypting the data so that other players cannot modify it, but the program/game will still be able to read the data for use otherwise.  My question then would be, is there a method of encryption where the game/program has a master key that can decrypt the data, but also the user can input their own password as a key to modify the data?  Thank you for your time.
I'll show a scheme with the following presumption:


the game has its own server key, this key is hidden in the game data somewhere (this usually cannot be secured completely, the game has to store the key somewhere);


So what you can do is to encrypt your game data with a randomly generated data key. If you use GCM mode of operation then you can verify if the data was tampered as well during decryption. This data key itself you encrypt (wrap) with the game key and the user key.

Now the game can always access and change the data. But the user needs to supply the user key. However, the user only has a password, so we need to convert that password to a user key. The way to do that is to use a Password Based Key Derivation Function such as PBKDF2, and use the output as the user key (note that you need to supply the PBKDF2 with a random salt that you generated &amp; stored when the user account is created).







In the end you can make it as easy or hard as you want. One very interesting feature would be to let the user sign the game data as well; in that case the game can reject tampered game data.

It may also be a good idea to encrypt game data values separately, you can use a hash of the identifier of the specific data as Initialization Vector for the encryption/decryption.