Friday, November 8, 2019

security - How can I protect my save data from casual hacking?


What options are there for saving game data in a secure manner? I'm interested in solutions specifically tailored for C++.


I'm looking for something that is fast and easy to use. I'm only concerned about storing simple information such as




  • Which levels are and are not unlocked





  • The user's score for each level




I'm curious again to know what's out there to use, any good libraries to use that give me nice, secure game data files that the average player can't mess with.


I just found this here which looks very nice, but it would be great to get some opinions on potential other libraries/options out there.



Answer



first lets say since you have a very simple save file, you can use text file.


one of the simplest ideas is to use a string key to lock/unlock data:



void encrypt(string& data,string key)
{
for(unsigned i=0;i data[i] += key[i%key.size()];
}

void decrypt(string& data,string key)
{
for(unsigned i=0;i data[i] -= key[i%key.size()];

}

but after a little google search I've found these links, which might be useful:



Edit:


Based on signed char being "Undefined behavior" as @v.oddou mentioned, I guess using XOR or casting to unsigned char will result in safer/more-cross-platform code. something like this:


void encrypt(string& data,string key)
{
for(unsigned i=0;i data[i] ^= key[i%key.size()];

}

void decrypt(string& data,string key)
{
for(unsigned i=0;i data[i] ^= key[i%key.size()];
}

No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...