1.下载OpenSSL的windows版本

32位:openssl-1.0.2a-i386-win32.zip

64位:openssl-1.0.2a-x64_86-win64.zip

下载之后解压即可使用,不过软件缺少配置文件

2.建立配置文件

在解压后的目录, 即openssl.exe所在目录新建配置文件,名为openssl-1.0.2a.cnf,内容如下

  1. # For use with easy-rsa version 2.0 and OpenSSL 1.0.0*
  2.  
  3. # This definition stops the following lines choking if HOME isn't
  4. # defined.
  5. HOME = .
  6. RANDFILE = $ENV::HOME/.rnd
  7. openssl_conf = openssl_init
  8.  
  9. [ openssl_init ]
  10. # Extra OBJECT IDENTIFIER info:
  11. #oid_file = $ENV::HOME/.oid
  12. oid_section = new_oids
  13. engines = engine_section
  14.  
  15. # To use this configuration file with the "-extfile" option of the
  16. # "openssl x509" utility, name here the section containing the
  17. # X.509v3 extensions to use:
  18. # extensions =
  19. # (Alternatively, use a configuration file that has only
  20. # X.509v3 extensions in its main [= default] section.)
  21.  
  22. [ new_oids ]
  23.  
  24. # We can add new OIDs in here for use by 'ca' and 'req'.
  25. # Add a simple OID like this:
  26. # testoid1=1.2.3.4
  27. # Or use config file substitution like this:
  28. # testoid2=${testoid1}.5.6
  29.  
  30. ####################################################################
  31. [ ca ]
  32. default_ca = CA_default # The default ca section
  33.  
  34. ####################################################################
  35. [ CA_default ]
  36.  
  37. dir = $ENV::KEY_DIR # Where everything is kept
  38. certs = $dir # Where the issued certs are kept
  39. crl_dir = $dir # Where the issued crl are kept
  40. database = $dir/index.txt # database index file.
  41. new_certs_dir = $dir # default place for new certs.
  42.  
  43. certificate = $dir/ca.crt # The CA certificate
  44. serial = $dir/serial # The current serial number
  45. crl = $dir/crl.pem # The current CRL
  46. private_key = $dir/ca.key # The private key
  47. RANDFILE = $dir/.rand # private random number file
  48.  
  49. x509_extensions = usr_cert # The extentions to add to the cert
  50.  
  51. # Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
  52. # so this is commented out by default to leave a V1 CRL.
  53. # crl_extensions = crl_ext
  54.  
  55. default_days = 3650 # how long to certify for
  56. default_crl_days= 30 # how long before next CRL
  57. default_md = md5 # use public key default MD
  58. preserve = no # keep passed DN ordering
  59.  
  60. # A few difference way of specifying how similar the request should look
  61. # For type CA, the listed attributes must be the same, and the optional
  62. # and supplied fields are just that :-)
  63. policy = policy_anything
  64.  
  65. # For the CA policy
  66. [ policy_match ]
  67. countryName = match
  68. stateOrProvinceName = match
  69. organizationName = match
  70. organizationalUnitName = optional
  71. commonName = supplied
  72. name = optional
  73. emailAddress = optional
  74.  
  75. # For the 'anything' policy
  76. # At this point in time, you must list all acceptable 'object'
  77. # types.
  78. [ policy_anything ]
  79. countryName = optional
  80. stateOrProvinceName = optional
  81. localityName = optional
  82. organizationName = optional
  83. organizationalUnitName = optional
  84. commonName = supplied
  85. name = optional
  86. emailAddress = optional
  87.  
  88. ####################################################################
  89. [ req ]
  90. default_bits = 1024
  91. default_keyfile = privkey.pem
  92. distinguished_name = req_distinguished_name
  93. attributes = req_attributes
  94. x509_extensions = v3_ca # The extentions to add to the self signed cert
  95.  
  96. # Passwords for private keys if not present they will be prompted for
  97. # input_password = secret
  98. # output_password = secret
  99.  
  100. # This sets a mask for permitted string types. There are several options.
  101. # default: PrintableString, T61String, BMPString.
  102. # pkix : PrintableString, BMPString (PKIX recommendation after 2004).
  103. # utf8only: only UTF8Strings (PKIX recommendation after 2004).
  104. # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
  105. # MASK:XXXX a literal mask value.
  106. string_mask = nombstr
  107.  
  108. # req_extensions = v3_req # The extensions to add to a certificate request
  109.  
  110. [ req_distinguished_name ]
  111. countryName = Country Name (2 letter code)
  112. countryName_default = CN
  113. countryName_min = 2
  114. countryName_max = 2
  115.  
  116. stateOrProvinceName = State or Province Name (full name)
  117. stateOrProvinceName_default = LiaoNing
  118.  
  119. localityName = Locality Name (eg, city)
  120. localityName_default = DaLian
  121.  
  122. 0.organizationName = Organization Name (eg, company)
  123. 0.organizationName_default = KEY_ORG
  124.  
  125. # we can do this but it is not needed normally :-)
  126. #1.organizationName = Second Organization Name (eg, company)
  127. #1.organizationName_default = World Wide Web Pty Ltd
  128.  
  129. organizationalUnitName = Organizational Unit Name (eg, section)
  130. #organizationalUnitName_default =
  131.  
  132. commonName = Common Name (eg, your name or your server\'s hostname)
  133. commonName_max = 64
  134.  
  135. name = Name
  136. name_max = 64
  137.  
  138. emailAddress = Email Address
  139. emailAddress_default = mail@host.domain
  140. emailAddress_max = 40
  141.  
  142. # JY -- added for batch mode
  143. organizationalUnitName_default = KEY_OU
  144. commonName_default = KEY_CN
  145. name_default = KEY_NAME
  146.  
  147. # SET-ex3 = SET extension number 3
  148.  
  149. [ req_attributes ]
  150. challengePassword = A challenge password
  151. challengePassword_min = 4
  152. challengePassword_max = 20
  153.  
  154. unstructuredName = An optional company name
  155.  
  156. [ usr_cert ]
  157.  
  158. # These extensions are added when 'ca' signs a request.
  159.  
  160. # This goes against PKIX guidelines but some CAs do it and some software
  161. # requires this to avoid interpreting an end user certificate as a CA.
  162.  
  163. basicConstraints=CA:FALSE
  164.  
  165. # Here are some examples of the usage of nsCertType. If it is omitted
  166. # the certificate can be used for anything *except* object signing.
  167.  
  168. # This is OK for an SSL server.
  169. # nsCertType = server
  170.  
  171. # For an object signing certificate this would be used.
  172. # nsCertType = objsign
  173.  
  174. # For normal client use this is typical
  175. # nsCertType = client, email
  176.  
  177. # and for everything including object signing:
  178. # nsCertType = client, email, objsign
  179.  
  180. # This is typical in keyUsage for a client certificate.
  181. # keyUsage = nonRepudiation, digitalSignature, keyEncipherment
  182.  
  183. # This will be displayed in Netscape's comment listbox.
  184. nsComment = "Easy-RSA Generated Certificate"
  185.  
  186. # PKIX recommendations harmless if included in all certificates.
  187. subjectKeyIdentifier=hash
  188. authorityKeyIdentifier=keyid,issuer:always
  189. extendedKeyUsage=clientAuth
  190. keyUsage = digitalSignature
  191.  
  192. # This stuff is for subjectAltName and issuerAltname.
  193. # Import the email address.
  194. # subjectAltName=email:copy
  195.  
  196. # Copy subject details
  197. # issuerAltName=issuer:copy
  198.  
  199. #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
  200. #nsBaseUrl
  201. #nsRevocationUrl
  202. #nsRenewalUrl
  203. #nsCaPolicyUrl
  204. #nsSslServerName
  205.  
  206. [ server ]
  207.  
  208. # JY ADDED -- Make a cert with nsCertType set to "server"
  209. basicConstraints=CA:FALSE
  210. nsCertType = server
  211. nsComment = "Easy-RSA Generated Server Certificate"
  212. subjectKeyIdentifier=hash
  213. authorityKeyIdentifier=keyid,issuer:always
  214. extendedKeyUsage=serverAuth
  215. keyUsage = digitalSignature, keyEncipherment
  216.  
  217. [ v3_req ]
  218.  
  219. # Extensions to add to a certificate request
  220.  
  221. basicConstraints = CA:FALSE
  222. keyUsage = nonRepudiation, digitalSignature, keyEncipherment
  223.  
  224. [ v3_ca ]
  225.  
  226. # Extensions for a typical CA
  227.  
  228. # PKIX recommendation.
  229.  
  230. subjectKeyIdentifier=hash
  231.  
  232. authorityKeyIdentifier=keyid:always,issuer:always
  233.  
  234. # This is what PKIX recommends but some broken software chokes on critical
  235. # extensions.
  236. #basicConstraints = critical,CA:true
  237. # So we do this instead.
  238. basicConstraints = CA:true
  239.  
  240. # Key usage: this is typical for a CA certificate. However since it will
  241. # prevent it being used as an test self-signed certificate it is best
  242. # left out by default.
  243. # keyUsage = cRLSign, keyCertSign
  244.  
  245. # Some might want this also
  246. # nsCertType = sslCA, emailCA
  247.  
  248. # Include email address in subject alt name: another PKIX recommendation
  249. # subjectAltName=email:copy
  250. # Copy issuer details
  251. # issuerAltName=issuer:copy
  252.  
  253. # DER hex encoding of an extension: beware experts only!
  254. # obj=DER:02:03
  255. # Where 'obj' is a standard or added object
  256. # You can even override a supported extension:
  257. # basicConstraints= critical, DER:30:03:01:01:FF
  258.  
  259. [ crl_ext ]
  260.  
  261. # CRL extensions.
  262. # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.
  263.  
  264. # issuerAltName=issuer:copy
  265. authorityKeyIdentifier=keyid:always,issuer:always
  266.  
  267. [ engine_section ]
  268. #
  269. # If you are using PKCS#11
  270. # Install engine_pkcs11 of opensc (www.opensc.org)
  271. # And uncomment the following
  272. # verify that dynamic_path points to the correct location
  273. #
  274. #pkcs11 = pkcs11_section
  275.  
  276. [ pkcs11_section ]
  277. engine_id = pkcs11
  278. dynamic_path = /usr/lib/engines/engine_pkcs11.so
  279. MODULE_PATH = changeme
  280. PIN = 1234
  281. init = 0

3.初始化一些参数

cmd切换到openssl目录,执行以下初始化内容

初始化内容包括,建立keys文件夹,生成index.txt空文本文件,生成serial文件内容为01

  1. rmdir /s /q keys
  2. mkdir keys
  3. copy /Y nul keys\index.txt
  4. echo 01 >keys\serial
  5. SET HOME=.
  6. SET KEY_DIR=keys

4.生成ca证书

这一步生成了2个文件:ca.key为CA的私钥文件,ca.crt为CA的证书文件,这两个文件后面的证书签名做准备

  1. openssl req -days 3650 -nodes -new -x509 -keyout keys\ca.key -out keys\ca.crt -config openssl-1.0.2a.cnf

5.生成服务端证书

生成服务器证书请求文件和服务器私钥

  1. openssl req -days 3650 -nodes -new -keyout keys\server.key -out keys\server.csr -config openssl-1.0.2a.cnf

CA签名

  1. openssl ca -days 3650 -out keys\server.crt -in keys\server.csr -extensions server -config openssl-1.0.2a.cnf

清除.old文件防止将来创建文件出现错误

  1. del /q keys\*.old

6.生成客户端证书

生成客户端证书请求文件和客户端私钥

  1. openssl req -days 3650 -nodes -new -keyout keys\client.key -out keys\client.csr -config openssl-1.0.2a.cnf

CA签名

  1. openssl ca -days 3650 -out keys\client.crt -in keys\client.csr -config openssl-1.0.2a.cnf

清除.old文件防止将来创建文件出现错误

  1. del /q keys\*.old

生成的证书文件都在keys文件夹中

笔者生成的证书下载:http://download.csdn.net/detail/gsls200808/8697633

Widows下利用OpenSSL生成证书的更多相关文章

  1. Linux下使用openssl生成证书

    利用OpenSSL生成库和命令程序,在生成的命令程序中包括对加/解密算法的测试,openssl程序,ca程序.利用openssl,ca可生成用于C/S模式的证书文件以及CA文件. 参考:http:// ...

  2. 如何利用OpenSSL生成证书

    此文已由作者赵斌授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 一.前言 最近为了测试内容分发网络(Content Delivery Network,简称 CDN)添加的新功 ...

  3. 【本地服务器】利用openssl生成证书

    (一)下载openssl软件,解压,进入bin目录 下载地址 (二)1.在当前bin目录,按住shift键右击,选择"在此处打开命令窗口" 2.打开cmd命令窗口之后,在窗口中输入 ...

  4. linux下利用openssl来实现证书的颁发(详细步骤)--转载和修改

    原文地址:http://www.cnblogs.com/firtree/p/4028354.html linux下利用openssl来实现证书的颁发(详细步骤) 1.首先需要安装openssl,一个开 ...

  5. linux下利用openssl来实现证书的颁发(详细步骤)

    1.首先需要安装openssl,一个开源的实现加解密和证书的专业系统.在centos下可以利用yum安装. 2.openssl的配置文件是openssl.cnf,我们一般就是用默认配置就可以.如果证书 ...

  6. 利用openssl管理证书及SSL编程第1部分: openssl证书管理

    利用openssl管理证书及SSL编程第1部分 参考:1) 利用openssl创建一个简单的CAhttp://www.cppblog.com/flyonok/archive/2010/10/30/13 ...

  7. 使用OpenSSL生成证书

    使用OpenSSL生成证书 下载安装openssl,进入/bin/下面,执行命令(把ssl目录下的openssl.cnf 拷贝到bin目录下)1.首先要生成服务器端的私钥(key文件):openssl ...

  8. Golang(十一)TLS 相关知识(二)OpenSSL 生成证书

    0. 前言 接前一篇文章,上篇文章我们介绍了数字签名.数字证书等基本概念和原理 本篇我们尝试自己生成证书 参考文献:TLS完全指南(二):OpenSSL操作指南 1. OpenSSL 简介 OpenS ...

  9. Windows 下使用OpenSSL生成RSA公钥和私钥

    Windows 下使用OpenSSL生成RSA公钥和私钥 (1)下载OpenSSL 可到该地址下载OpenSSL: https://www.openssl.org/source/(https://ww ...

随机推荐

  1. 【linux】【磁盘分割】Linux磁盘分割

    全部的磁盘阵列容量均给/cluster/raid目录,占有2TB的容量: 2 GB的swap容量: 分割出/, /usr, /var, /tmp等目录,避免程序错误造成系统的困扰: /home也独立出 ...

  2. Kubernetes的主要功能

    Kubernetes的主要功能 1.数据卷   Pod中容器之间共享数据,可以使用数据卷. 2.应用程序健康检查   容器内服务可能进程堵塞无法处理请求,可以设置监控检查策略保证应用健壮性. 3.复制 ...

  3. GoF23种设计模式之行为型模式之责任链模式

    一.概述 使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系.将这些对象连成一条链,并且沿着这条链传递请求,直到有一个对象处理它为止.其设计思想是:给对多个对象处理一个请求的机会, ...

  4. Linux实现内容分发的主备模式的智能DNS

    BIND实现智能DNS的原理是通过view的方式,首先判断客户请求的来源,然后返回不同的IP 规划:为za.com域进行智能解析 分2个网段,192.168.1.0/24网段的请求解析到192.168 ...

  5. spring+struts2+mybatis框架依赖pom.xml

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  6. HDU:4185-Oil Skimming

    Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Proble ...

  7. selenium2中TestNG相关解释

    testNg官网:http://testng.org/doc/documentation-main.html 新建testNG class的时候,同时也新建了一个TestNG.xml的文件. 此xml ...

  8. 线程中更新ui方法汇总

    一.为何写作此文   你是不是经常看到很多书籍中说:不能在子线程中操作ui,不然会报错.你是不是也遇到了如下的疑惑(见下面的代码): @Override protected void onCreate ...

  9. debug环境下打印

    #ifdef DEBUG #    define NSLog(...) NSLog(__VA_ARGS__) #else #    define NSLog(...) {} #endif

  10. PHP 开启或关闭错误提示

    如果不具备修改 php.ini 的权限,可以如下: // 只需在php文件中加入这两句即可开启PHP错误提示 ini_set("display_errors", "On& ...