This article transferred from: http://kb.cnblogs.com/page/94467/
OpenSSL is a security protocol that provides security and data integrity for network communications, encompassing key cryptographic algorithms, common key and certificate encapsulation management functions, and SSL protocols, and provides a rich range of applications for testing or other purposes.
First download the OpenSSL package: (http://www.openssl.org/), this is a C language library package, under Windows can be makebuild through Perl to the class library, generating Libeay32, Ssleay32 Lib and DLL files, see: http://blogger.org.cn/blog/more.asp?name=OpenSSL&id=18972, compile to produce such a series of files:
Inc32 inside the C language header file.
1. Now I want to use it in VS2010 project, first I want to create a VC + +. NET project, I have created an MFC application here:
In the project name, click "Right", select "Properties", from the inside to find "VC + + Directory":
Two directory options found:
The directory that contains the directory pointing to your OpenSSL's header file, which points to your LIB, the directory where the DLL resides.
From here, create a new directory to point to the boot directory:
Then switch to "linker", "input":
In additional dependencies, add two lib files:
This completes the reference to the static library.
2. Now look at how to reference it in the project (take the SHA256 algorithm as an example):
#include <openssl/sha.h>
Methods Show:
?
1234567891011121314 |
// SHA256算法字符串加密
void sha256(
char
* string,
char outputBuffer[64])
{
unsigned
char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, string,
strlen
(string));
SHA256_Final(hash, &sha256);
int i = 0;
for
(i = 0; i < SHA256_DIGEST_LENGTH; i++)
{
sprintf
(outputBuffer + (i * 2),
"%02x"
, hash[i]);
}
}
|
Call:
?
12 |
static unsigned char buffer[64]; sha256(signature, ( char *)buffer); |
Since the OpenSSL package needs to be compiled using Perl to form Lib and DLL files, I enclose the files that have been made so that they can be used easily!
OpenSSL latest version of OPENSSL-1.0.0D's Windows execution Pack download: Openssl_out32dll.rar
[Go] Reference lib Static library in VS2010 VC + + project (for example, OpenSSL)