I'm working on a program and it contains lots of strings. I wan't to make it impossible to change these strings using hex editor. So the question is how can i do that ?
Yes but it seems i still can see the strings using hex editor until i write only encrypted string. Like this:
1 2 3 4 5 6 7 8 9 10
unsignedchar *out = OUT_OF_A_STRING;
unsignedchar *out2 = calloc(SIZE+1, sizeof(char));
BF_KEY *key = calloc(1, sizeof(BF_KEY));
/* set up a test key */
BF_set_key(key, SIZE, (constunsignedchar*)"TestKey!" );
/* test out decryption */
BF_ecb_encrypt(out, out2, key, BF_DECRYPT);
printf("%s\n", out2);
So it means i have to get "out" of all of my strings and replace them all and then i have to add encrypt codes for every one of them. I have many strings and it will take a long time with this method.
Is there any way to make this method(or any other method) for all strings automatically or something with less trouble to modify the strings ?
Clearly, you wouldn't store the keys in the program. Nor would you sore the strings you want to encode (the plain text). You're place the encrypted strings (cypher text) in the program and supply the key at runtime.
I've already posted everything, there's nothing else. I didn't use an IDE project, I just compiled the files from the command line using g++ as shown. It works on Windows (cygwin), OS X and Linux as is and requires OpenSSL (devel) be installed.
You have to build the excutable showstr from showstr.cpp and str.cpp as I mention at the end. If you think about it, that's of the point, as showstr is displaying the strings we compiled into str.cpp.
It occured to me that the password could be stored in str.cpp in cleartext. As the idea is just to obscure the strings in the program, there's no harm in doing so, and the program can decode the strings without requireing the user to enter a password.
Also, as Blowfish encrypts 64bit blocks, you're restricted to 8 byte strings. But I would expect you to remove this restriction once you understood how the whole thing hangs together. I wrote it late at night and didn't want to spend time dealing with that issue at the time (or now either).