openssl C代码笔记

openssl实例。
环境:ubuntu 16.04 64 bit。

一、安装

1
sudo apt-get install libssl-dev openssl

二、生成证书

1
sudo openssl genrsa -out privkey.pem 2048

genrsa表示生成rsa密钥,-out指定输出文件为privkey.pem,最后的2048是私钥大小,这里用默认值2048。

1
$ sudo openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1024

req -new表示生成一个新证书请求,-key指定用到的私钥文件(即上面已经生成的privkey.pem),-out指定证书文件为cacert.pem,-days表示证书有效期,单位为天数,默认是365,这里改为1024。

执行过程如下,其中“:”为手动输入信息,也可直接回车:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:Guangxi
Locality Name (eg, city) []:nanning
Organization Name (eg, company) [Internet Widgits Pty Ltd]:CST Studio
Organizational Unit Name (eg, section) []:CST
Common Name (e.g. server FQDN or YOUR name) []:Late Lee
Email Address []:li@latelee.org

三、代码

待写

  • 本文作者:李迟
  • 版权声明:原创文章,版权归署名作者,转载建议注明出处(当然不注明亦可)。
  • 本文链接:/toolslib/openssl-c-code.html