• windows10 qt5 mingw32编译cryptopp563


    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:cryptopp552fipstest.cpp and replace every 'OutputDebugString' with 'OutputDebugStringA'. (3 replacements in total)

    don't forget to save it!

    delete the C:cryptopp552GNUmakefile

    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 elease and C:cryptopp552debug

    copy the C:cryptopp552 eleaselibcryptopp552.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 eleasecryptopp552.dll to <Qt dir>in

    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>includecryptopp.

    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: releasecryptopptest.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 << " CryptoPP::Exception caught: "

                  << e.what() << endl;

           return -1;

        }

        catch(std::exception &e)

        {

           cout << " std::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!

  • 相关阅读:
    LAMP----linux+apache+mysql+php详细安装步骤之一APACHE篇(openldap等)
    Apache2 httpd.conf 配置详解
    Apache+php+mysql的安装与配置
    linux PHP 安装及 GD库安装
    Linux下安装PHP的GD支持库
    linux下tar.gz、tar、bz2、zip等解压缩、压缩命令
    Android中Context详解 ---- 你所不知道的Context(转)
    Android简单文件浏览器源代码 (转)
    Android入门之文件系统操作(一)简单的文件浏览器 (转)
    Android入门之文件系统操作
  • 原文地址:https://www.cnblogs.com/cute/p/5680592.html
Copyright © 2020-2023  润新知