Briefly
OpenSSL is a strong Secure Sockets Layer cipher library that includes key cryptographic algorithms, common key and certificate encapsulation management functions, and SSL protocols, and provides a rich set of applications for testing or other purposes.
- Briefly
- Download installation
- Use
- More references
Download installation
Go to the Win32 OpenSSL download page and select the version that is appropriate for your download.
After the download is complete, I select the directory for the installation D:\Program Files\OpenSSL-Win32
. Into the installation directory, you can see that the following folders are mainly included:
Lib: Contains all the library files (for example: Libeay32.lib, Ssleay32.lib).
Include: Contains all the header files (for example: Aes.h, md5.h).
Bin: Contains a test program, a file that stores certificates and keys (*.PEM).
If you want to compile yourself, refer to: Compiling OpenSSL under windows
Use
Include library files and paths in Pro.
+= -L"D:/Program Files/OpenSSL-Win32/lib" -llibeay32LIBS += -L"D:/Program Files/OpenSSL-Win32/lib" -lssleay32INCLUDEPATH += $$quote(D:/Program Files/OpenSSL-Win32/include)
You can then use the sha256 as an example to encrypt the string.
#include <openssl/ssl.h>STD::string sha256 (const std::< Span class= "hljs-built_in" >string str) {char buf[2]; unsigned char hash[sha256_digest_length]; Sha256_ctx sha256; Sha256_init (&sha256); Sha256_update (&sha256, Str.c_str (), str.size ()); Sha256_final (hash, &sha256); std::string newstring = ""; for (int i = 0; i < SHA256_DIGEST_ LENGTH; i++) {sprintf (Buf, "%02x", Hash[i]); newstring = newString + buf ; } return newstring;}
Take "Hello world", for example, to verify.
int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); std::string str = "Hello World"; qDebug() << QString::fromStdString(sha256(str)); return a.exec();}
Output result: "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e"
In order to determine whether the output is correct, we can conduct online verification on the Internet.
More references
- Windows compiles OpenSSL
- Openssl
- How to Include OpenSSL in a Qt project
- Building OpenSSL for Visual Studio
- How do I compile OpenSSL under Windows?
http://blog.csdn.net/liang19890820/article/details/51611400
QT directly uses the functions in OpenSSL