Listing Listing - 27 days ago 18
C++ Question

Compile-time string encryption

I don't want reverse-engineers to read the plain-text of hardcoded strings in my application. The trivial solution for this is using a simple XOR-Encryption. The problem is I need a converter and in my application it will look like this:

//Before (unsecure)
char * cString = "Helllo Stackoverflow!";
//After (secure)
char * cString = XStr( 0x06, 0x15, 0x9D, 0xD5FBF3CC, 0xCDCD83F7, 0xD1C7C4C3, 0xC6DCCEDE, 0xCBC2C0C7, 0x90000000 ).c();


Is there the possibility to maintain clean code by using some construct like

//Before (unsecure)
char * cString = "Helllo Stackoverflow!";
//After (secure)
char * cString = CRYPT("Helllo Stackoverflow!");


It should also work for quite long strings ( 1000 characters? :-) ). Thank you in advance

Answer

This blog provides a solution for compile time string hashing in C++. I guess the principle is the same. Unfortunately You have to create one Makro for each string length.