VC2008下編譯OpenSSL
kagula
2012-3-21
環境:
WinXPSP3、ActivePerl-5.12.4.1205、OpenSSL 1.0.1
正文:
[1]ActivePerl-5.12.4.1205-MSWin32-x86-294981.zip解壓縮後,啟動
"Visual Studio 2008 Command Prompt",在指令行中轉到Perl解壓縮後的
路徑執行“Installer.bat”指令。
[2]解壓縮openssl-1.0.1.tar.gz到E:\SDK (你也可以是其它路徑)
啟動"Visual Studio 2008 Command Prompt"
>cd E:\SDK\openssl-1.0.1
運作Configure
>perl Configure VC-WIN32 no-asm
生成Makefile檔案
>ms\do_ms
編譯靜态庫
>nmake -f ms\nt.mak
編譯好的靜态庫在E:\SDK\openssl-1.0.1\out32
如果你還編譯了動态庫,動态庫在E:\SDK\openssl-1.0.1\out32dll路徑
[3]
VS2008下配置頭搜尋路徑
E:\SDK\openssl-1.0.1\include
VS2008下配置庫搜尋路徑
E:\SDK\openssl-1.0.1\out32
[4]下面是檢查OpenSSL環境是否已經配置好的測試源碼
#include <string>
#include <iostream>
#include <openssl/md5.h>
#pragma comment(lib, "libeay32.lib")
#pragma comment(lib, "ssleay32.lib")
int _tmain(int argc, _TCHAR* argv[])
{
std::string str = "1234";
std::string strMd5 = "";
unsigned char md[MD5_DIGEST_LENGTH];
char tmp[3] = {0};
MD5((const unsigned char*)str.c_str(), str.size(), md);
for (int i = 0; i < MD5_DIGEST_LENGTH; i++)
{
sprintf_s(tmp, "%02X", md[i]);
strMd5.append(tmp);
}
std::cout<<strMd5<<std::endl;
return 0;
}
[5]列出證書的幾種使用方式
使用方式1:
發送者發送[1]證書(隻帶公鑰)[2]簽名過的資料(相當于“文摘”)[3]未簽名過的資料(明文)[4]DN
給接收者
接收者
[1]資料完整性檢查
[1-1]對明文進行簽名,生成本地簽名(相當于“文摘”)
[1-2]本地簽名,同遠端簽名過的資料相比較,如果一緻,說明資料完整
[2]發送者真實性檢查
[2-1]從遠端簽名過的資料裡提驗證書
[2-2]兩個證書的某個資訊和DN中的資訊相比較是否一緻,如果一緻,說明發送者是真實的。
使用方式2:
發送者發送[1]證書(隻帶公鑰) [2]密文 [3]明文
給接收者
接收者[1]驗證證書合法
[2]用證書中的公鑰對密文解碼
(私鑰隻有發送者知道,隻有發送者才能編碼,保證發送者的真實性。)
[3]解碼後的明文,和發送過來的明文相比較
驗證是否資料被篡改過,如果沒有,驗證成功。
相關網址
[1]《ActivePerl》
http://www.activestate.com/activeperl/
[2]《openss》
http://www.openssl.org/
[3]《vc2008編譯openssl》
http://lanhy2000.blog.163.com/blog/static/4367860820109179208885/
[4]《VC2008下使用OpenSSL 1.0.0g(免編譯)》
http://blog.csdn.net/akof1314/article/details/7241829
[5]《VC++網絡安全程式設計範例(12)-PKI程式設計》
http://www.cnblogs.com/yincheng01/archive/2011/12/17/2311155.html