openssl安裝
首先安裝perl工具,下載地址:
Download & Install Perl - ActiveStateDownload Perl 5.32 and 5.28 from ActiveState & get precompiled Perl distribution. ActiveState Perl is free to download.https://www.activestate.com/activeperl/downloads
我下載了 這個(gè)版本(安裝過程下一步下一步即可)
我安裝在 C:\Perl64
然后下載openssl:
/source/index.htmlhttps://www.openssl.org/source/
下載壓縮包
下載后解壓在 perl 同一個(gè)目錄下
安裝Visual Studio2013
下載 Visual Studio Tools - 免費(fèi)安裝 Windows、Mac、Linux
三個(gè)都安裝完成后,檢查環(huán)境變量
C:\Program Files (x86)\Microsoft Visual Studio12.0\VC\bin;
C:\Perl64\bin;
c:\windows\system32
接下來開始關(guān)鍵部分
1、打開VC開發(fā)人員命令工具:(以管理員身份運(yùn)行)
?使用cd命令將目錄指向D:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin(PS:自己的VC安裝路徑),?命令行鍵入vcvars32,運(yùn)行vcvars32.bat..完成后進(jìn)入OpenSSL源碼的目錄(C:\openssl)
2、編譯配置 (cd到OpenSSL目錄下)
在命令行中鍵入"perl configure VC-WIN32 no-asm --prefix=c:\openssl"(PS:--prefix=c:\openssl命令為指定安裝位置)
輸出一大串后
3、創(chuàng)建Makefile文件
輸入nmake命令 這次會(huì)輸出很多東西,稍微等命令執(zhí)行完。
4、然后輸入 nmake test
可以打開openssl目錄下的 install 文件看里面的說明安裝過程來安裝
這里有不同操作系統(tǒng)下的安裝步驟
5、接下來 輸入 nmake install
上訴4中執(zhí)行結(jié)果最后 會(huì)有個(gè) pass ,表示通過 即可install了 ,如果沒通過需要查看test中輸出的錯(cuò)誤并解決。
openssl生成私鑰
介紹
openssl genrsa 用于生成rsa私鑰文件,生成是可以指定私鑰長度和密碼保護(hù)。
語法
openssl genrsa[-out filename] [-passout arg] [-des] [-des3] [-idea] [-f4] [-3] [-rand file(s)] [-engine id] [numbits]
選項(xiàng)說明:
-out filename:私有密鑰輸出文件名,缺省為標(biāo)準(zhǔn)輸出。
-passout arg:輸出文件口令保護(hù)存放方式。
-f4:指定E為0x1001;
-3:指定E為3;
-rand file(s):隨機(jī)種子。
-engine id:硬件引擎。
numbits:生成密鑰的位數(shù)。必須是本指令的最后一個(gè)參數(shù)。如果沒有指明,則產(chǎn)生512bit長的參數(shù)。
-des|-des3|-idea|-aes128|-aes192|-aes256:指定私鑰口令保護(hù)算法,如果不指定,私鑰將被明文存放。
一般使用
[cpp]?view plain?copy
- E:\OpenSSL\foo>openssl?genrsa?-out?rsa_pri.pme??
- Loading?'screen'?into?random?state?-?done??
- Generating?RSA?private?key,?512?bit?long?modulus??
- .++++++++++++??
- ...............++++++++++++??
- e?is?65537?(0x10001)??
從輸出可以看出,密鑰長度是512bit。我們也可以指定密鑰長度,密鑰長度越長越安全,但使用密鑰進(jìn)行加解密時(shí)所耗費(fèi)的時(shí)間也會(huì)變長。非對稱密鑰提高安全性的同時(shí)也帶來了算法所耗費(fèi)的大量時(shí)間,非對稱密鑰不對大塊數(shù)據(jù)進(jìn)行加密,應(yīng)用領(lǐng)域是數(shù)字簽名,密鑰分發(fā)等小數(shù)據(jù)加密。
numbits?? 密鑰長度(單位bit)
[cpp]?view plain?copy
- openssl?genrsa?-out?rsa_pri.pem?1024??
-passout?arg
對生成的rsa私鑰文件施加密碼保護(hù),例如:使用idea算法對私鑰文件進(jìn)行密碼保護(hù)。
[cpp]?view plain?copy
- openssl?genrsa??-idea?-passout?pass:123?-out?rsa_pri.pem??
-F4 / -3??? 指數(shù)(我不知道,算法里面的東西吧),默認(rèn)是65537,例如上例中輸出的最后一句話,e is 65537 (0x10001)
[cpp]?view plain?copy
- E:\OpenSSL\foo>openssl?genrsa??-3??-out?rsa_pri.pem?2000??
- Loading?'screen'?into?random?state?-?done??
- Generating?RSA?private?key,?2000?bit?long?modulus??
- ......................+++??
- .............+++??
- e?is?3?(0x3)??
使用openssl生成證書
創(chuàng)建私鑰
openssl genrsa -out ca-key.pem -des 1024
文件名為 ca-key.pem 長度為1024,以des加密方式存放 ,不加-des是明文方式
?
密碼 我輸了1234
文件默認(rèn)生成在當(dāng)前目錄下
?
通過CA私鑰生成CSR
csr:
對于服務(wù)器SSL證書, 在申請服務(wù)器數(shù)字證書時(shí)一定要先在服務(wù)器上生成 CSR 文件 ( Certificate Signing Request 證書簽名請求文件)
openssl req -new -key ca-key.pem -out ca-csr.pem
?
通過CSR文件和私鑰生成CA證書
openssl x509 -req -in ca-csr.pem -signkey ca-key.pem -out ca-cert.pem
?
ok 這樣就創(chuàng)建好了CA證書
下面這個(gè)是一個(gè)例子,創(chuàng)建服務(wù)器端證書,在csr生成是加入了配置文件,用CA證書來創(chuàng)建服務(wù)器的證書,
最后加入了一個(gè)打包證書的操作。
創(chuàng)建服務(wù)器端證書
為服務(wù)器生成私鑰
openssl genrsa -out server-key.pem -des 1024
密碼1234
利用服務(wù)器私鑰文件服務(wù)器生成CSR
openssl req -new -key server-key.pem -config openssl.cnf -out server-csr.pem
新建一個(gè)配置文件 openssl.cnf 輸入以下配置信息:
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
[req_distinguished_name]
countryName = Country Name (2 letter code)
countryName_default = CN
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = BeiJing
localityName = Locality Name (eg, city)
localityName_default = YaYunCun
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = Domain Control Validated
commonName = Internet Widgits Ltd
commonName_max = 64
[ v3_req ]
# Extensions to add to a certificate request
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names
[alt_names]
#注意這個(gè)IP.1的設(shè)置,IP地址需要和你的服務(wù)器的監(jiān)聽地址一樣
IP.1 = 127.0.0.1
---------------------------------配置文件結(jié)束----------------------------
通過服務(wù)器私鑰文件和CSR文件生成服務(wù)器證書
openssl x509 -req -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -in server-csr.pem -out server-cert.pem -extensions v3_req -extfile openssl.cnf
打包證書
openssl pkcs12 -export -in server-cert.pem -inkey server-key.pem -certfile ca-cert.pem -out server.pfx文章來源:http://www.zghlxwxcb.cn/news/detail-477890.html
export密碼1234文章來源地址http://www.zghlxwxcb.cn/news/detail-477890.html
到了這里,關(guān)于openssl安裝,openssl生成私鑰以及openssl生成證書的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!