FileSource privFile(privFilename, true, new HexDecoder);
RSAES_OAEP_SHA_Decryptor priv(privFile);
string result;
StringSource(ciphertext, true, new HexDecoder(new PK_DecryptorFilter(GlobalRNG(), priv, new StringSink(result))));
return result; [Page]
}
//------------------------
// 定义全局的随机数池
//------------------------
RandomPool & GlobalRNG()
{
static RandomPool randomPool;
return randomPool;
}
2.设置工程属性
选择工程属性(Alt + F7):
(1)“Configuration Properties”→“C/C++” →“General”,右边的“Additional Include Directories”设置为上面建好的Crypto++ SDK的Include文件夹,“C:\\Program Files\\CyptoPP\\include”;
(2) “Configuration Properties”→“Linker” →“General”,右边的“Additional Library Directories”设置为上面建好的Crypto++ SDK的Lib\\Debug文件夹,“C:\\Program Files\\CyptoPP\\lib\\debug”(Release模式下对应着Release文件夹);
(3) “Configuration Properties”→“C/C++” →“Code Generation”,右边的“Runtime Library”设置为“Multi-threaded Debug (/MTd)”(Release模式下对应着“Multi-threaded (/MT)”)
3.运行程序(Ctrl + F5)
正常运行的输出结果为:
Origin Text: Hello World!
Encrypted Text: 79C72A482482EF45111F961772456310792AB735ECF72329ECB26292D2B26374
824E0E35D24A63CB03B867DD2C70B001FD4B2B33FBC984BD229A5226F284B889901817976A680322
9E8351372C5E28E8BEBA2A94E7CF61A8A162F0BA2F3E0C35D26842D92EC4866D25E6BF878743E481
84D9F6FF9BA690F953568D017C02D540
Decrypted Text: Hello World!
如果上面的第(3)步没有设置则会出现以下链接错误:
cryptlib.lib(randpool.obj) : error LNK2005: \"public: __thiscall std::basic_string,class std::allocator >::basic_string,class std::allocator >(char const *)\" ( 0 $basic_string@DU $char_traits@D@std@@V $allocator@D@2@@std@@QAE@PBD@Z) already defined in msvcprtd.lib(MSVCP80D.dll)
说在msvcprtd.lib和MSVCRTD.lib中已经定义过。