windows10 qt5 mingw32编译cryptopp563

参考链接:

http://www.qtcentre.org/threads/28809-Compiling-amp-using-Crypto-with-mingw-version-of-Qt

Compiling & using Crypto++ with mingw version of Qt

Hi pals!

I personally had much trouble with these.

apparently compiled version of crypto++ (cryptopp530win32win64.zip) is build using MSVC and does not work with mingw.

fortunately I could get it to work finally.

so I tell you too, step by step, how to do it.

first download the cryptopp552.zip (crypto++ v5.5.2 sources)

why cryptopp552.zip? apparently this is the latest version that is successfully compiled with mingw.

extract the contents of the cryptopp552.zip to C:\cryptopp552

edit the C:\cryptopp552\fipstest.cpp and replace every 'OutputDebugString' with 'OutputDebugStringA'. (3 replacements in total)

don't forget to save it!

delete the C:\cryptopp552\GNUmakefile

open the Qt command prompt (I used that of the Qt SDK 2009.05)

input the following commands at the Qt command line:

c:

cd \cryptopp552

qmake -project

open the cryptopp552.pro (that is now created in C:\cryptopp552)

in it:

change TEMPLATE = app to TEMPLATE = lib

add a line containing LIBS += -lws2_32 at the end.

type the following commands at the Qt command line:

qmake

mingw32-make all

wait for the build process to finish (may take many minutes)

now we should have files named libcryptopp552.a and cryptopp552.dll in directories C:\cryptopp552\release and C:\cryptopp552\debug

copy the C:\cryptopp552\release\libcryptopp552.a to <Qt dir>\lib

note that there is another directory named lib one level higher in the Qt SDK installation dir. So don't confuse them please.

copy the C:\cryptopp552\release\cryptopp552.dll to <Qt dir>\bin

note that there is another directory named bin one level higher in the Qt SDK installation dir. So don't confuse them please.

create a directory named cryptopp in <Qt dir>\include.

copy all header (.h) files from the C:\cryptopp552 to <Qt dir>\include\cryptopp.

now we can test crypto++ and see how to use it in our Qt programs.

first example is a program that computes an MD5 hash (of a hard coded string):

main.cpp

Qt Code: Switch view

#include <iostream>

#define CRYPTOPP_DEFAULT_NO_DLL

#include <cryptopp/dll.h>

#ifdef CRYPTOPP_WIN32_AVAILABLE

#include <windows.h>

#endif

#include <cryptopp/md5.h>

USING_NAMESPACE(CryptoPP)

USING_NAMESPACE(std)

const int MAX_PHRASE_LENGTH=250;

int main(int argc, char *argv[]) {

CryptoPP::MD5 hash;

byte digest[ CryptoPP::MD5::DIGESTSIZE ];

std::string message = "Hello World!";

hash.CalculateDigest( digest, (const byte*)message.c_str(), message.length());

CryptoPP::HexEncoder encoder;

std::string output;

encoder.Attach( new CryptoPP::StringSink( output ) );

encoder.Put( digest, sizeof(digest) );

encoder.MessageEnd();

std::cout << "Input string: " << message << std::endl;

std::cout << "MD5: " << output << std::endl;

return 0;

}

To copy to clipboard, switch view to plain text mode

code from: http://www.cryptopp.com/wiki/Hash_Functions

remember that you should add these lines to its .pro file before starting to build it:

LIBS += -lcryptopp552

CONFIG+=console

the program should print these on the console window:

Input string: Hello World!

MD5: ED076287532E86365E841E92BFC50D8C

second example is a program that takes 3 arguments at the command line.

arguments are file names.

the program then prompts for a Passphrase and then stores an encrypted version of the first file in the second file and then stores the result of decrypting the second file in the third file.

sample command line I used: release\cryptopptest.exe 1.jpg 2.jpg 3.jpg

Qt Code: Switch view

#include <iostream>

#define CRYPTOPP_DEFAULT_NO_DLL

#include <cryptopp/dll.h>

#include <cryptopp/default.h>

#ifdef CRYPTOPP_WIN32_AVAILABLE

#include <windows.h>

#endif

USING_NAMESPACE(CryptoPP)

USING_NAMESPACE(std)

const int MAX_PHRASE_LENGTH=250;

void EncryptFile(const char *in,

                    const char *out,

                    const char *passPhrase);

void DecryptFile(const char *in,

                    const char *out,

                    const char *passPhrase);

int main(int argc, char *argv[])

{

   try

    {

       char passPhrase[MAX_PHRASE_LENGTH];

       cout << "Passphrase: ";

       cin.getline(passPhrase, MAX_PHRASE_LENGTH);

       EncryptFile(argv[1], argv[2], passPhrase);

       DecryptFile(argv[2], argv[3], passPhrase);

    }

    catch(CryptoPP::Exception &e)

    {

       cout << "\nCryptoPP::Exception caught: "

              << e.what() << endl;

       return -1;

    }

    catch(std::exception &e)

    {

       cout << "\nstd::exception caught: " << e.what() << endl;

       return -2;

    }

}

void EncryptFile(const char *in,

                    const char *out,

                    const char *passPhrase)

{

    FileSource f(in, true, new DefaultEncryptorWithMAC(passPhrase,

                   new FileSink(out)));

}

void DecryptFile(const char *in,

                    const char *out,

                    const char *passPhrase)

{

    FileSource f(in, true,

         new DefaultDecryptorWithMAC(passPhrase, new FileSink(out)));

}

RandomPool & GlobalRNG()

{

    static RandomPool randomPool;

    return randomPool;

}

int (*AdhocTest)(int argc, char *argv[]) = NULL;

To copy to clipboard, switch view to plain text mode

code from: http://www.codeguru.com/cpp/misc/mis...le.php/c11953/

remember that you should add these lines to its .pro file before starting to build it:

LIBS += -lcryptopp552

CONFIG+=console

--------------------------------

I appreciate your feedback.

good luck!

根据上面内容修改,但是编译报错:

'CryptoPP::memcpy_s' has not been declared

修改config.h 打开 CRYPTOPP_WANT_SECURE_LIB的选项

// Define this if you want or need the library's memcpy_s and memmove_s.

//   See http://github.com/weidai11/cryptopp/issues/28.

#if !defined(CRYPTOPP_WANT_SECURE_LIB)

# define CRYPTOPP_WANT_SECURE_LIB

#endif

重新编译,OK!

windows10 qt5 mingw32编译cryptopp563的更多相关文章

  1. Qt打开外部程序和文件夹需要注意的细节(Qt调用VC写的动态库,VC需要用C的方式输出函数,否则MinGW32编译过程会报错)

    下午写程序中遇到几个小细节,需要在这里记录一下. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 QProcess *process = new QProcess(this ...

  2. vs2017+qt5.x编译32位应用<转>

    原文地址:https://www.cnblogs.com/woniu201/p/10862170.html 概述 最近有同学私信我,问如何使用vs2017+qt5.10编译出32位的应用,需要使用ms ...

  3. 【Qt开发】vs2017+qt5.x编译32位应用

    概述 最近有同学私信我,问如何使用vs2017+qt5.10编译出32位的应用,需要使用msvc2017_x86的插件,然而qt官网并没有提供,只能使用源码编译生成msvc2017_x86插件,使用n ...

  4. 【转帖】嵌入式4412开发板QT5.7编译安装到arm

    QT5.7.0+UBUNTU16.04+ARM-NONE-LINUX-GNUEABI4.8+busybox最小LINUX系统 Orandragon记录 本文转自迅为4412开发板群:http://to ...

  5. [ffmpeg 扩展第三方库编译系列] 关于libopenjpeg mingw32编译问题

    在mingw32如果想编译libopenjpeg 会比较麻烦 会出现undefined reference to `_imp__opj_destroy_cstr_info@4' 等错误 因此编译时候需 ...

  6. qwt6在Windows下Qt5的编译,安装,初步使用

    今晚把qwt的编译,安装,初级使用放上来,以便需要的人,能更快部署好编程环境,不至于每次都像我这样花很多时间. 注意:Qtcreater使用的是什么编译器编译出来的,就要用那个编译器来编译qwt. 我 ...

  7. QT5.6 编译SQLServer驱动

    简要说下编译的主要步骤 @1:打开vs2015的命令行编译环境 ‘ @2:进入到cd到源码目录:cd C:\Qt\Qt5.6.0\5.6\Src\qtbase\src\plugins\sqldrive ...

  8. QT5静态编译教程,主要针对vs2012(渡世白玉)

    QT5,VS2012静态编译,所有的库准备充分的话qwebkit也可以静态编译通过,但是我编译的版本使用中如果用了QWEBVIEW控件在连接时会出错. 注:我自己编译的环境是:win server 2 ...

  9. 【Qt】Qt5.12编译MySQl5.7驱动(亲自测试成功)

    目录 00. 目录 01. 安装Qt5.12 02. 打开MySQL源码项目 03. 编译MySQL驱动代码 04. 修改mysql.pro文件 05. 编译之后得到对应的库 06. 拷贝动态库到指定 ...

随机推荐

  1. 【转】详解Python的装饰器

    原文链接:http://python.jobbole.com/86717/ Python中的装饰器是你进入Python大门的一道坎,不管你跨不跨过去它都在那里. 为什么需要装饰器 我们假设你的程序实现 ...

  2. 【java】: 操作excel2007/2003

    //上传位置(与操作excel无关,可不看) public String getUploadPath() { File theWebFolder = XMPPServer.getInstance(). ...

  3. monkeyrunner功能函数

    MonkeyRunner Command Summary 1. #导入模块;    from com.android.monkeyrunner import MonkeyRunner, MonkeyD ...

  4. 占位符(placeholder text)

    占位符(placeholder text)是用户在input(输入)框输入任何东西之前放置在input(输入)框中的预定义文本. 你可以用如下方式创建占位符: <input type=" ...

  5. Codeforces #256 Div.2

    B. Suffix Structure 1. 先判断s去掉一些元素是否能构成t,如果可以就是automaton 判断的方法也很简单,two pointer,相同元素同时++,不相同s的指针++,如果t ...

  6. 慧都独家披露DevExpress v13.2测试版重大变化

    昨日,DevExpress隆重宣布发布v13.2.3测试版,想抢先尝鲜的朋友可以在这里下载哦.希望使用DevExpress旧版本的朋友,看到这些更新后能尽快更新你的代码,以免造成不必要的麻烦. Das ...

  7. DM9000网卡驱动接受数据从中断方式改成NAPI方式小记

    平台是最最经典的s3c2440了,说了要做这件事情很久了,就是改几行代码,一直没有做.前几天逼了自己一下,终于给做了,拖延症患者伤不起. 以下是需要读者对napi机制有所熟悉: step1:在boar ...

  8. (原创)即使最可怕的自然力量,也不失美丽——火山喷发(摄影,欣赏)

    文中图片摘自腾讯文化:www.cal.qq.com 1.Abstract     最可怕的力量也潜含着最美丽的风景奇观,虽然不能亲眼目睹,但透过大师的视角,一样也能体会到自然力量撼动的美丽. 2.Co ...

  9. 《理解 ES6》阅读整理:函数(Functions)(一)Default Parameter Values

    对于任何语言来说,函数都是一个重要的组成部分.在ES6以前,从JavaScript被创建以来,函数一直没有大的改动,留下了一堆的问题和很微妙的行为,导致在JavaScript中使用函数时很容易出现错误 ...

  10. 利用dbms_metadata.get_ddl查看DDL语句

    http://www.cnblogs.com/aocle/archive/2011/10/13/2209790.html 当我们想要查看某个表或者是表空间的DDL的时候,可以利用dbms_metada ...