关于加密程序
開發(fā)加密程序時(shí),有很多種加密算法可以選擇,blowfish,AES,還有簡(jiǎn)單的異或運(yùn)算啦等等
其實(shí)這些都不是關(guān)鍵,關(guān)鍵點(diǎn)是如何隱藏加密算法的key
如果將key作為明文保存在程序中,很容易在數(shù)據(jù)段中查看到相應(yīng)的值
從而失去了加密的意義
?
由此可見,一個(gè)關(guān)鍵點(diǎn)在于隱藏key字符
使用boost庫(kù)的序列化宏,可以簡(jiǎn)單的實(shí)現(xiàn)隱藏key的功能
代碼如下:
1 #define CRYPT_MACRO(r, d, i, elem) ( elem ^ ( d - i ) ) 2 3 #include <boost/preprocessor/cat.hpp> 4 #include <boost/preprocessor/seq/for_each_i.hpp> 5 #include <boost/preprocessor/seq/enum.hpp> 6 7 #define DEFINE_HIDDEN_STRING(NAME, SEED, SEQ)\ 8 static const char* BOOST_PP_CAT(Get, NAME)()\ 9 {\ 10 static char data[] = {\ 11 BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_FOR_EACH_I(CRYPT_MACRO, SEED, SEQ)),\ 12 '\0'\ 13 };\ 14 \ 15 static bool isEncrypted = true;\ 16 if ( isEncrypted )\ 17 {\ 18 for (unsigned i = 0; i < ( sizeof(data) / sizeof(data[0]) ) - 1; ++i)\ 19 {\ 20 data[i] = CRYPT_MACRO(_, SEED, i, data[i]);\ 21 }\ 22 \ 23 isEncrypted = false;\ 24 }\ 25 \ 26 return data;\ 27 } 28 29 //32116D937A114CF68FBA11E55F4B7150 30 //258795D85B004823B5546DB33E055F0D 31 32 DEFINE_HIDDEN_STRING(EncryptionKey1, 0x7f, ('3')('2')('1')('1')('6')('D')('9')('3')('7')('A')('1')('1')('4')('C')('F')('6')('8')('F')('B')('A')('1')('1')('E')('5')('5')('F')('4')('B')('7')('1')('5')('0')) 33 DEFINE_HIDDEN_STRING(EncryptionKey2, 0x5d, ('2')('5')('8')('7')('9')('5')('D')('8')('5')('B')('0')('0')('4')('8')('2')('3')('B')('5')('5')('4')('6')('D')('B')('3')('3')('E')('0')('5')('5')('F')('0')('D')) 34 35 const char* GetEncodeKey1(void) 36 { 37 return GetEncryptionKey1(); 38 } 39 40 const char* GetEncodeKey2(void) 41 { 42 return GetEncryptionKey2(); 43 }原始的key是由guid生成器生成,將key序列化打亂之后,在程序的二進(jìn)制數(shù)據(jù),代碼段,數(shù)據(jù)段都不會(huì)找到key的原始數(shù)據(jù)了
轉(zhuǎn)載于:https://www.cnblogs.com/jojodru/p/4757729.html
總結(jié)
- 上一篇: 机务最好进哪些航空公司?
- 下一篇: 银寨在哪里 探寻银寨所在地?