openssl
命令格式:
openssl command [ command_opts ] [ command_args ]
子命令分为三类:
1、Standard commands 标准命令:包含genrsa、ca、req、x509之类用于自签证书的命令和passwd、rand等其他常用命令
2、Message Digest commands 单向加密命令:dgst
支持md2、md4、md5、sha、sha1、rmd160算法
格式:openssl dgst
[-sha|-sha1|-mdc2|-ripemd160|-sha224|-sha256|-sha384|-sha512|-md2|-md4|-md5|-dss1] [-c][-d] [-hex] [-binary] [-out filename][file...]
3、Cipher commands,对称加密命令:enc
支持aes-126-cbc、cast、des、rc4、des3等60多种加密算法
格式:openssl enc -ciphername [-in filename] [-out filename] [-e] [-d] [-a/-base64] [-k password] [-kfile filename] [-K key] [-S salt] [-salt] [-nosalt]
-e 加密
-d 解密
-a base64
-k 解密密钥
-salt 加料
自建CA
1、创建CA所需相关目录及文件(系统默认/etc/pki/CA/)
ca
├── certs 证书目录
├── crl 证书吊销目录
├── newcerts CA 签发的证书备份
├── private 私钥目录
├
├── index.txt CA 签发证书列表
└── serial CA 下一次签发证书时使用的序列号
2、生成CA私钥:
cd /etc/pki/CA
openssl genrsa -out private/ca.key NUM(私钥位数)
3、签发CA证书
openssl req -new -x509 -key private/ca.key -out cacert.pem -days 3650
用户证书
1、生成用户证书私钥
openssl genrsa -out /root/user.key 2048
2、生成用户证书签发请求(.csr)
openssl req -new -key /root/user.key -out /root/user.csr -days 365
3、发送给CA所在主机签发
openssl ca -in /root/user.csr -out /root/user.crt -days 365
其他证书操作
查看证书的内容:$ openssl x509 -in cert.pem -text -noout
吊销证书:$ openssl ca -revoke cert.pem -config openssl.cnf
证书吊销列表:$ openssl ca -gencrl -out cacert.crl -config openssl.cnf
查看列表内容:$ openssl crl -in cacert.crl -text -noout