openssl编译及使用

源码地址:https://github.com/openssl/openssl.git

分支OpenSSL_1_0_2-stable在windows10编译

1.使用ActiveState Perl工具
有nasm工具,启用汇编文件

1
2
perl Configure VC-WIN32 --prefix=c:\some\openssl\dir
ms\do_nasm

无nasm工具

1
2
perl Configure VC-WIN32 no-asm --prefix=c:/some/openssl/dir
ms\do_ms

2.使用nmake工具
在开始菜单中找到vs的开发工具命令提示,使用如下命令

1
2
3
4
5
6
// 编译
nmake -f ms\ntdll.mak
// 测试
nmake -f ms\ntdll.mak test
// 安装
nmake -f ms\ntdll.mak install

openssl证书转换

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Convert a DER file (.crt .cer .der) to PEM
openssl x509 -inform der -in certificate.cer -out certificate.pem

// Convert a PEM file to DER
openssl x509 -outform der -in certificate.pem -out certificate.der

// Convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to PEM
openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes

// You can add -nocerts to only output the private key or add -nokeys to only output the certificates.
// Convert a PEM certificate file and a private key to PKCS#12 (.pfx .p12)
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

// Convert PEM to CRT (.CRT file)
openssl x509 -outform der -in certificate.pem -out certificate.crt

OpenSSL Convert PEM

1
2
3
4
5
6
7
8
// Convert PEM to DER
openssl x509 -outform der -in certificate.pem -out certificate.der

// Convert PEM to P7B
openssl crl2pkcs7 -nocrl -certfile certificate.cer -out certificate.p7b -certfile CACert.cer

// Convert PEM to PFX
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

OpenSSL Convert DER

1
2
Convert DER to PEM
openssl x509 -inform der -in certificate.cer -out certificate.pem

OpenSSL Convert P7B

1
2
3
4
5
6
7
Convert P7B to PEM
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

Convert P7B to PFX
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

openssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx -certfile CACert.cer

OpenSSL Convert PFX

1
2
Convert PFX to PEM
openssl pkcs12 -in certificate.pfx -out certificate.cer -nodes