In c++, can you write to a file that cannot be read by any program other than that...

jehovaswalrus

New member
...program? I understand that you can use any file extension you want when creating the file, but all a smart person has to do is assign Notepad to it and it can be read and edited without the help of my program.
 
Unless you are just saving pure text this isn't normally an issue. If it is then just write to it using encryption. Instead of using the standard file io functions write one of your own which modify the data .
At its simplest just shift the data a few bits i.e.

void MyWrite(file* pfile, int size, char* buffer)
{
for(int i=0;i<size;i++)
{
char modified = buffer+i;
modified = modified + 5;
fprintf(pfile,"%c", modified);
}
}

If you want something more complex and more secure use a look up table or a "real" encryption algorithm.
When you read it back in do the opposite
 
You can :

1) Use encryption (e.g. you can XOR byte after byte with a random byte sequence -the key- to encode/decode).
2) Keep your application running all the time (from boot to shut down) and at the same time keeping the file openned with the appropriate file permissions (this provides no actual security for your data).
 
You can :

1) Use encryption (e.g. you can XOR byte after byte with a random byte sequence -the key- to encode/decode).
2) Keep your application running all the time (from boot to shut down) and at the same time keeping the file openned with the appropriate file permissions (this provides no actual security for your data).
 
Back
Top