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命令使用的更多相关文章

  1. OpenSSL命令系列

    1.1 ssl命令系列前言 openssl命令的格式是"openssl command command-options args",command部分有很多种命令,这些命令需要依赖 ...

  2. openssl命令用法

    openssl命令 配置文件:/etc/pki/tls/openssl.cnf 命令格式: openssl command [ command_opts ] [ command_args ] 众多子命 ...

  3. openssl命令行工具简介 - 指令x509

    原文链接: http://blog.csdn.net/allwtg/article/details/4982507 openssl命令行工具简介 - 指令x509 用法:           open ...

  4. 使用openssl命令剖析RSA私钥文件格式

    原文 https://blog.csdn.net/zhymax/article/details/7683925 Openssl提供了强大证书功能,生成密钥对.证书,颁发证书.生成crl.验证证书.销毁 ...

  5. openssl命令实例

    基本知识 1,证书标准 X.509 X.509 - 这是一种证书标准,主要定义了证书中应该包含哪些内容.其详情可以参考RFC5280,SSL使用的就是这种证书标准. X.509的证书文件,一般以.cr ...

  6. 用OpenSSL命令行生成证书文件

    用OpenSSL命令行生成证书文件 1.首先要生成服务器端的私钥(key文件): openssl genrsa -des3 -out server.key 1024 运行时会提示输入密码,此密码用于加 ...

  7. (2) OpenSSL命令

    openssl命令的格式是"openssl command command-options args",command部分有很多种命令,这些命令需要依赖于openssl命令才能执行 ...

  8. (转)openssl 命令: openssl req 命令详解

                                      openssl req命令主要的功能有,生成证书请求文件, 查看验证证书请求文件,还有就是生成自签名证书.本文就主要记录一下open ...

  9. OpenSSL命令---pkcs8

    用途: pkcs8格式的私钥转换工具.它处理在PKCS#8格式中的私钥文件.它可以用多样的PKCS#5 (v1.5 and v2.0)和 PKCS#12算法来处理没有解密的PKCS#8 Private ...

  10. openssl命令行工具简介 - RSA操作

    原文链接: http://www.cnblogs.com/aLittleBitCool/archive/2011/09/22/2185418.html 首先介绍下命令台下openssl工具的简单使用: ...

随机推荐

  1. 利用百度翻译API批量翻译文本

    有时间再做总结! # coding=utf-8 #authority:bing #2017-7-18 import httplib import md5 import urllib import ur ...

  2. Bootstrap 基本css样式

    1.标题1级标题<h1> 38px 是默认大小的2.7倍2级标题<h2> 32px 是默认大小的2.25倍3级标题<h3> 24px 是默认大小的1.70倍4级标题 ...

  3. P2053 [SCOI2007]修车 费用流

    $ \color{#0066ff}{ 题目描述 }$ 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的.现在需要安排这M ...

  4. Reviewing notes 2.1 of Mathematical analysis

    Chapter2 Numerical sequence and function Cartesian product set If S and T are sets,then the cartesia ...

  5. Qt 学习之路 2(42):QListWidget、QTreeWidget 和 QTableWidget

    Qt 学习之路 2(42):QListWidget.QTreeWidget 和 QTableWidget 豆子 2013年2月5日 Qt 学习之路 2 38条评论 上一章我们了解了 model/vie ...

  6. java 连接 Redis

    使用 jedis-2.9.0.jar 包 连接 Docker 中的 Redis 容器. package redisTest; /** * @Author:YangLianjun * @Descript ...

  7. [BZOJ 1489][HNOI2009]双递增序

    传送门 满满的负罪感,昨晚的刷题历程:写几道难题吧-->算了,还是只切道水题吧-->RNG赢了...... 背包一下就行了 #include <bits/stdc++.h> u ...

  8. Services版本tomcat 内存和perm 设置

    当在tomcat的webapps文件夹中部署需要大量资源的war包时,启动tomcat,war包将不能被成功部署. tomcat安装有services版安装和开发版安装. 本经验将介绍如何设置两种版本 ...

  9. ZOJ - 2401 水DP

    最近会多做点巩固基础的题目 #include<iostream> #include<algorithm> #include<cstdio> #include< ...

  10. 页面加载时的div动画

    用@keyframes(动画),实现页面加载时的div动画(不要用js控制,因为当页面加载的时候,js还不一定可以使用) 可以在https://daneden.github.io/animate.cs ...