openssl命令使用
openssl
openssl是个密码工具集,提供多端接口调用方式
组成:
1. 代码库 libcryto ,libssl(ssl/tls)
2. 工具集 openssl
对称加密
对称加密主要是用aes,des算法
需要注意的是解密不要在源文件操作,否则解密失败源文件也没有了
usage: enc -ciphername [-AadePp] [-base64] [-bufsize number] [-debug]
[-in file] [-iv IV] [-K key] [-k password]
[-kfile file] [-md digest] [-none] [-nopad] [-nosalt]
[-out file] [-pass arg] [-S salt] [-salt]
-e 指定加密算法
-d 解密
-a 使用base64编码
-base64 使用base64解码
-in 要加密文件存放位置
-out 加密后的文件存放位置
-k 输入密码
-iv 输入一个向量
加密
$ openssl enc -e aes-128-cbc -in secret.txt -out myAes128.txt
解密
$ openssl enc -d aes-128-cbc -in myAes128.txt -out
单向散列函数加密
使用最多的是sha256,sha512,hmac
md5不再推荐使用,推荐使用sha-2
单向散列函数特点
1.输出值的数据长度不变
2.相同的输入输出也必定相同
3.输入相似的数据,输出也大不相同
4.输入完全不同的数据,输出相同的哈希值会以极低的概率出现
单向散列函数的使用
openssl dgst
options are
-c to output the digest with separating colons
-r to output the digest in coreutils format
-d to output debug info
-hex output as hex dump
-binary output in binary form
-hmac arg set the HMAC key to arg
-verify file verify a signature using public key in file
-prverify file verify a signature using private key in file
-keyform arg key file format (PEM or ENGINE)
-out filename output to filename rather than stdout
-signature file signature to verify
-sigopt nm:v signature parameter
-hmac key create hashed MAC with key
-mac algorithm create MAC (not neccessarily HMAC)
-md4 to use the md4 message digest algorithm
-md5 to use the md5 message digest algorithm
-ripemd160 to use the ripemd160 message digest algorithm
-sha to use the sha message digest algorithm
-sha1 to use the sha1 message digest algorithm
-sha224 to use the sha224 message digest algorithm
-sha256 to use the sha256 message digest algorithm
-sha384 to use the sha384 message digest algorithm
-sha512 to use the sha512 message
$ cat test.txt | openssl dgst -sha256 -hex -out hash.txt
生成随机数
随机数的作用
1. 生成密钥: 用于对称密码和消息认证码
2. 生成密钥对:用于公钥密码和数字签名
3. 生成初始化向量(IV):用于分组密码的CBC,CFB和OFB模式
4. 生成nonce, 用于防御重放攻击以及分组密码的CTR模式等
5. 生成盐,用于基于口令的密码(PBE)等
生成随机数
openssl rand [option] 字节数
where options are
-out file - write to file
-engine e - use engine e, possibly a hardware device.
-rand file:file:... - seed PRNG from files
-base64 - base64 encode output
-hex - hex encode output
$ openssl rand -hex 1
$ openssl rand -base64 10 -out a.txt
生成口令密钥
一般基于口令的密钥为了防止字典攻击会使用一串随机数加入单向散列函数
openssl passwd
Usage: passwd [options] [passwords]
where options are
-crypt standard Unix password algorithm (default)
-1 MD5-based password algorithm
-apr1 MD5-based password algorithm, Apache variant
-salt string use provided salt
-in file read passwords from file
-stdin read passwords from stdin
-noverify never verify when reading password from terminal
-quiet no warnings
-table format output as table
-reverse switch table columns
$ openssl passwd -salt 123
生成密钥对
首先使用genrsa生成私钥,然后在使用rsa从私钥中提取公钥
openssl genrsa
usage: genrsa [args] [numbits]
-des encrypt the generated key with DES in cbc mode
-des3 encrypt the generated key with DES in ede cbc mode (168 bit key)
-idea encrypt the generated key with IDEA in cbc mode
-seed
encrypt PEM output with cbc seed
-aes128, -aes192, -aes256
encrypt PEM output with cbc aes
-camellia128, -camellia192, -camellia256
encrypt PEM output with cbc camellia
-out file output the key to 'file
-passout arg output file pass phrase source
-f4 use F4 (0x10001) for the E value
-3 use 3 for the E value
-engine e use engine e, possibly a hardware device.
$ openssl genrsa -out rsa.key 2048
//生成公钥
$ openssl rsa -in rsa.key -pubout -out rsa-public.key
证书
对证书所发布的公钥进行权威的认证,证书可以有效的避免中间人攻击的问题
1. PKC:Public-Key Certificate,公钥证书,简称证书。
2. CA:Certification Authority,认证机构。对证书进行管理,负责 1.生成密钥对、2. 注册公钥时对身份进行认证、3. 颁发证书、4. 作废证书。其中负责注册公钥和身份认证的,称为 RA(Registration Authority 注册机构)
3. PKI:Public-Key Infrastructure,公钥基础设施,是为了更高效地运用公钥而制定的一系列规范和规格的总称。比较著名的有PKCS(Public-Key Cryptography Standards,公钥密码标准,由 RSA 公司制定)、X.509 等。PKI 是由使用者、认证机构 CA、仓库(保存证书的数据库)组成。
CRL:Certificate Revocation List 证书作废清单,是 CA 宣布作废的证书一览表,会带有 CA 的数字签名。一般由处理证书的软件更新 CRL 表,并查询证书是否有效。
4.证书的编码格式:pem,der
证书的申请签署步骤

1. 生成申请请求
2. RA验证
3. CA签署
4. 获取证书
(1)创建所需要的文件
touch /etc/pki/CA/index.txt 生成证书索引数据库文件
echo 01 > /etc/pki/CA/serial 指定第一个颁发证书的序列号
(2)CA自签证书
(1)生成私钥
cd /etc/pki/CA/
(umask 066; openssl genrsa -out
/etc/pki/CA/private/cakey.pem 2048)
(2)生成自签名证书
openssl req -new -x509 –key
/etc/pki/CA/private/cakey.pem -days 7300 -out
/etc/pki/CA/cacert.pem
-new: 生成新证书签署请求
-x509: 专用于CA生成自签证书
-key: 生成请求时用到的私钥文件
-days n:证书的有效期限
-out /PATH/TO/SOMECERTFILE: 证书的保存路径
(3)颁发证书
A 在需要使用证书的主机生成证书请求
给web服务器生成私钥
(umask 066; openssl genrsa -out
/etc/pki/tls/private/test.key 2048)
生成证书申请文件
openssl req -new -key /etc/pki/tls/private/test.key
-days 365 -out etc/pki/tls/test.csr
B 将证书请求文件传输给CA
C CA签署证书,并将证书颁发给请求者
openssl ca -in /tmp/test.csr –out
/etc/pki/CA/certs/test.crt -days 365
注意:默认国家,省,公司名称三项必须和CA一致
D 查看证书中的信息:
openssl x509 -in /PATH/FROM/CERT_FILE -noout
-text|issuer|subject|serial|dates
openssl ca -status SERIAL 查看指定编号的证书状态
(4) 吊销证书
A 在客户端获取要吊销的证书的serial
openssl x509 -in /PATH/FROM/CERT_FILE -noout
-serial -subject
B 在CA上,根据客户提交的serial与subject信息,对比检验是
否与index.txt文件中的信息一致,吊销证书:
openssl ca -revoke /etc/pki/CA/newcerts/SERIAL.pem
C 指定第一个吊销证书的编号
注意:第一次更新证书吊销列表前,才需要执行
echo 01 > /etc/pki/CA/crlnumber
D 更新证书吊销列表
openssl ca -gencrl -out /etc/pki/CA/crl/crl.pem
查看crl文件:
openssl crl -in /etc/pki/CA/crl/crl.pem -noout -text
openssl命令使用的更多相关文章
- OpenSSL命令系列
1.1 ssl命令系列前言 openssl命令的格式是"openssl command command-options args",command部分有很多种命令,这些命令需要依赖 ...
- openssl命令用法
openssl命令 配置文件:/etc/pki/tls/openssl.cnf 命令格式: openssl command [ command_opts ] [ command_args ] 众多子命 ...
- openssl命令行工具简介 - 指令x509
原文链接: http://blog.csdn.net/allwtg/article/details/4982507 openssl命令行工具简介 - 指令x509 用法: open ...
- 使用openssl命令剖析RSA私钥文件格式
原文 https://blog.csdn.net/zhymax/article/details/7683925 Openssl提供了强大证书功能,生成密钥对.证书,颁发证书.生成crl.验证证书.销毁 ...
- openssl命令实例
基本知识 1,证书标准 X.509 X.509 - 这是一种证书标准,主要定义了证书中应该包含哪些内容.其详情可以参考RFC5280,SSL使用的就是这种证书标准. X.509的证书文件,一般以.cr ...
- 用OpenSSL命令行生成证书文件
用OpenSSL命令行生成证书文件 1.首先要生成服务器端的私钥(key文件): openssl genrsa -des3 -out server.key 1024 运行时会提示输入密码,此密码用于加 ...
- (2) OpenSSL命令
openssl命令的格式是"openssl command command-options args",command部分有很多种命令,这些命令需要依赖于openssl命令才能执行 ...
- (转)openssl 命令: openssl req 命令详解
openssl req命令主要的功能有,生成证书请求文件, 查看验证证书请求文件,还有就是生成自签名证书.本文就主要记录一下open ...
- OpenSSL命令---pkcs8
用途: pkcs8格式的私钥转换工具.它处理在PKCS#8格式中的私钥文件.它可以用多样的PKCS#5 (v1.5 and v2.0)和 PKCS#12算法来处理没有解密的PKCS#8 Private ...
- openssl命令行工具简介 - RSA操作
原文链接: http://www.cnblogs.com/aLittleBitCool/archive/2011/09/22/2185418.html 首先介绍下命令台下openssl工具的简单使用: ...
随机推荐
- 自定义内核启动后的Logo
1.使用图像GIMP工具 2.详细步骤如下: A.将800x480的图片导入到GIMP工具. B.选中GIMP菜单栏进行以下操作 图像 -->模式 ...
- spring配置文件中导入约束的详细步骤
这里先以<beans>元素为例: 首先在eclipse中引入相关约束: 点击OK后,这个约束就被引入到eclipse中了,这一步的意义在于:就算你处于脱机情况下(不能联网),也能给你提示. ...
- ZOJ Monthly, January 2019 Little Sub and his Geometry Problem ZOJ4082(模拟 乱搞)
在一次被自己秀死... 飞机 题目: 给出N,K, Q; 给出一个N*N的矩阵 , 与K个特殊点 , 与Q次查询 , 每次查询给出一个C , 问 在这个N*N矩阵中 , 有多少的点是满足这样的一个关 ...
- 将M个客服随机分配给N个客户
class AllocUser { //客户多于客服 public static void Test() { var customers = new List<Customer>() { ...
- 使用手淘flexible.js适配移动端布局
下载flexible: https://github.com/amfe/lib-flexible //未压缩版 (function flexible (window, document) { var ...
- dcoker machine
Docker Machine是一个安装和管理 Docker 的工具, 它有自己的命令行工具:docker-machine.Docker Machine简化了Docker的安装和远程管理, 不仅可以管理 ...
- docker 解决容器时间与主机时间不一致的问题
环境: 1.阿里云ecs服务器 2.docker 3.docker镜像 centos7.4.1708 方法一: 查看主机时间: [root@iZbp1625jeg61bc2zzfcotZ docker ...
- springboot项目中引用其他springboot项目jar
1. 剔除要引入的springboot项目中不需要的文件:如Application和ApplicationTests等 2.打包 不能使用springboot项目自带的打包插件进行打包: 3.打包 4 ...
- pinyin4j的基本使用
PinYin4jUtils工具类代码:http://www.cnblogs.com/jepson6669/p/8856082.html maven中引入依赖 <!-- 引入pinyin4J的依赖 ...
- React.js 小书 Lesson8 - 组件的组合、嵌套和组件树
作者:胡子大哈 原文链接:http://huziketang.com/books/react/lesson8 转载请注明出处,保留原文链接和作者信息. 继续拓展前面的例子,现在我们已经有了 Heade ...