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工具的简单使用: ...
随机推荐
- 【ExecutorService】概述
初试 今天做一个上传excel,后台异步导入数据功能,使用ExecutorService private final ExecutorService m_longPollingService; pub ...
- springboot集成巨杉数据库
springboot倾向于约定优于配置,所以大大简化了搭建项目的流程,包括各种数据源的配置,接下来就和大家分享下最近用到的巨杉数据源连接池的配置 1.现在配置文件中定义巨杉连接池的各种连接信息,至于每 ...
- quartz实例以及主要事项(注解)
实现任务类: package com.vnetoo.nec.base.quartz; import org.springframework.context.annotation.Lazy;import ...
- hdu 6196 搜索+剪枝
Today, Bob plays with a child. There is a row of n numbers. One can takes a number from the left sid ...
- java基础_02
一.this和super 作用: this:区分成员变量和局部变量 super:区分父类的成员变量和局部变量 用法: this.成员变量名://访问本类的成员变量 this.成员方法名()://访问本 ...
- flask总结01
一:Flask的基本介绍和小案例 01:flask的基本介绍 Flask诞生于2010年,是Armin ronacher(人名)用 Python 语言基于 Werkzeug 工具箱编写的轻量级Web开 ...
- 116th LeetCode Weekly Contest N-Repeated Element in Size 2N Array
In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeate ...
- UVA - 10817 状压DP
题意:大白P95 本题比较特别的是状压两个集合并且进行转移,因此要分别处理当前集合只有1个老师/2个老师的记录(然后可O(1)得出0个老师的集合) 记忆化过了但是迭代式不能记忆超过2的之前的状态是怎样 ...
- [转] 如何批量删除Docker中已经停止的容器
[From]https://blog.csdn.net/csdn_duomaomao/article/details/78587103 方法一: #显示所有的容器,过滤出Exited状态的容器,取出这 ...
- 2019.3.20 I/O相关
I/O 相关简介 什么是I/O? IO,即Input (输入)和Output (输出)的首字母缩写. 什么是流? 流(Stream)是抽象概念,它代表任何有能力产出数据的数据源对象或者是与能力接收数据 ...