设为首页 加入收藏

TOP

Crypto++ 的使用方法 (二)
2014-11-23 22:53:50 来源: 作者: 【 】 浏览:5
Tags:Crypto 使用方法
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中已经定义过。

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇MFC各种指针的获取 下一篇 fork与进程地址空间

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: