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工具的简单使用: ...
随机推荐
- Shell等,不等......
-eq //等于 -ne //不等于 -gt //大于 (greater ) -lt //小于 (less) -g ...
- python中html解析
import requestsfrom bs4 import BeautifulSoup url = "..." payload =...headers = None respon ...
- P3615 如厕计划
$ \color{#0066ff}{ 题目描述 }$ 竞赛比完之后,水箱里充满水的选手们鱼贯而出.凡华中学的厕所规划的很糟,只有两个厕位,于是厕所门前排起了长长的队伍. 厕所有两个,一个是女生专用厕所 ...
- 基于linux内核包过滤技术的应用网关
目录 基于linux内核包过滤技术的应用网关 硬件形态 基本原理 应用场景 主要功能 其他功能 客户定制 基于linux内核包过滤技术的应用网关 硬件形态 基本原理 应用场景 媒体内容过滤和深度识别 ...
- C++_IO与文件5-文件的输入与输出
大多数计算机程序都使用了文件.文件本身是存储在某种设备上的一系列字节. 通常,操作系统管理文件,跟踪它们的位置.大小.创建时间等. 除非在操作系统级别上编程,否则通常不必担心这些事情. 真正需要的是将 ...
- POJ3322 Bloxorz I 无脑广搜(我死了。。。)
多测不清空,爆零两行泪....我死了QWQ 每个节点3个状态:横坐标,纵坐标,和方向 说一下方向:0:立着,1:竖着躺着,上半部分在(x,y),2:横着躺着,左半部分在(x,y) 然后就有了常量数组: ...
- wzoi(栈模拟)
链接:https://ac.nowcoder.com/acm/contest/332/I 来源:牛客网 题目描述 bleaves 最近在 wzoi 上面做题. wzoi 的题目有两种,一种是 noip ...
- Python面向对象之元类(metaclass)
点进来看就完事了铁汁!
- Python-is, ==, cmp()
is 主要是判断 2 个变量是否引用的是同一个对象,如果是的话,则返回 true,否则返回 false. 判断数字相等不要用 is 操作符 1 2 3 4 5 6 7 8 9 10 11 12 > ...
- gym 100589A queries on the Tree 树状数组 + 分块
题目传送门 题目大意: 给定一颗根节点为1的树,有两种操作,第一种操作是将与根节点距离为L的节点权值全部加上val,第二个操作是查询以x为根节点的子树的权重. 思路: 思考后发现,以dfs序建立树状数 ...