1、在 CentOS7 中使用 gpg 创建 RSA 非对称密钥对
[root@centos7 ~]# gpg --gen-key
[root@centos7 ~]# gpg --list-keys
2、将 CentOS7 导出的公钥,拷贝到 CentOS8 中,在 CentOS8 中使用 CentOS7 的公钥加密一个文件
[root@centos7 ~]# gpg -a --export -o xxx.pubkey
[root@centos7 ~]# scp xxx.pubkey centos8
[root@centos8 ~]# gpg --gen-key
[root@centos8 ~]# gpg --list-keys
[root@centos8 ~]# gpg --import -o xxx.pubkey
[root@centos8 ~]# gpg -e -r abcd file
3、回到 CentOS7 服务器,远程拷贝 file.txt.gpg 文件到本地,使用 CentOS7的私钥解密文件
[root@centos7 ~]# scp file.gpg centos7
[root@centos7 ~]# gpg -d file.gpg
[root@centos7 ~]# gpg -o file -d file.gpg
4、在 CentOS7 中使用 openssl 软件创建 CA
1)创建CA所需要的文件
#生成证书索引数据库文件
touch /etc/pki/CA/index.txt
#指定第一个颁发证书的序列号
echo 01 > /etc/pki/CA/serial
2)生成CA私匙
cd /etc/pki/CA/(umask 066; openssl genrsa -out private/cakey.pem 2048)
3)生成CA自签名证书
openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 3650 -out /etc/pki/CA/cacert.pem
5、 在 CentOS7 中使用 openssl 软件创建一个证书申请请求文件,并使用上面的跟证书对其进行签署
1)为需要使用证书的主机生成生成私钥 (umask 066; openssl genrsa -out /data/test.key 2048)
2)为需要使用证书的主机生成证书申请文件
openssl req -new -key /data/test.key -out /data/test.csr
3)在CA签署证书并将证书颁发给请求者
注意:默认要求国家,省,公司名称三项必须和CA一致
openssl ca -in /data/test.csr -out /etc/pki/CA/certs/test.crt -days 100
4)查看证书中的信息:2.4.3
openssl x509 -in /PATH/FROM/CERT_FILE -noout -text|issuer|subject|serial|dates
#查看指定编号的证书状态openssl ca -status SERIAL
6、吊销已经签署成功的证书
在客户端获取要吊销的证书的serial
openssl x509 -in /PATH/FROM/CERT_FILE -noout -serial -subject
在CA上,根据客户提交的serial与subject信息,对比检验是否与index.txt文件中的信息一致,吊销证书:
openssl ca -revoke /etc/pki/CA/newcerts/SERIAL.pem
指定第一个吊销证书的编号,注意:第一次更新证书吊销列表前,才需要执行
echo 01 > /etc/pki/CA/crlnumber
更新证书吊销列表
openssl ca -gencrl -out /etc/pki/CA/crl.pem
查看crl文件:
openssl crl -in /etc/pki/CA/crl.pem -noout -text