当前位置:网站首页>加密与解密以及OpenSSL的应用
加密与解密以及OpenSSL的应用
2022-06-30 20:39:00 【星哥玩云】
本文主要简单介绍下;
一、数据加密的三种方式;
二、Openssl的基础应用以及创建CA证书与发证;
一、数据加密的三种方式;
1、对称加密;加密与解密方使用同一个算法, 将数据切割成数据块逐步加密,并且前后块之间有关联关系,被称为块量,解密就是拿到块量做运算,进行解密。
常用的对称加密算法有:
DES(56bits), 3DES, AES(128bits), Blowfish
Twofish, IDEA, RC6, CAST5, Serpent
特点;加密与解密使用同一个口令
将原文分割成固定大小数据块,对这些数据块进行加密
加密数度快
缺点;口令传输,安全性不高
口令太多,不易于记忆
2、公钥加密(也称非对称加密);与对称加密算法的主要差别在于,加密和解密的密钥不相同,一个公开(公钥),一个保密(私钥)。解决了对称加密算法密钥分配管理的问题,提高了算法安全性。
非对称算法有;RSA、EIGamal、DSA
特性;发送方数据传输时是用接收方的公钥加密,接收方用自己的私钥解密。
身份认证是发送方用自己的私钥加密,接收方用对方的公钥解密以此来保证数据安全性。
缺点;非对称加密算法的加密、解密的效率比较低。
3、单向加密,对数据按照一定和算法生成特征码,具有不可逆性。
抽取数据特征码的算法有;MD5, SHA1, SHA512, CRC-32
消息认证算法;CBC-MAC、HMAC
特性;
消息认证;只用于验证消息本身,需要加密特征码。
雪崩效应;输入数据的微小改变,会导致结果大的变化。
定长输出;无任输入数据多长,只要使用同一种单向加密算法,输出结果的长度都相同。
结合以上三种加密方法:如下图所示;
上图所示,把三种加密算法结合起来使用,对称加密实现了数据的机密性,公钥加密实现身份认证,而单向加密则实现了数据的完整性。
二、Openssl的基础应用以及创建CA证书与发证;
1)、Openss是一套用于SSL(安全套接字层)/TLS(传输层安全)协议的加密工具,有如下三个组件组成;
1、libcrypto;通用功能加密库;
2、libssl;用于实现SSL/TLS的功能
3、多功能命令工具
其作用还可以生成密钥、创建数字证书、计算信息摘要、手动加密解密数据。
2)、对称加密以及解密的方法;
常用算法有:DES,3DES,AES,Blowfish,Twofish,RC6,CAST5
加密; openssl enc -des3 -a -salt -in /etc/issue -out /tmp/issue_cipher [[email protected] ~]# cat /etc/issue 没加密前的内容 CentOS release 6.5 (Final) Kernel \r on an \m [[email protected] ~]# openssl enc -des3 -a -salt -in /etc/issue -out /tmp/issue_cipher enter des-ede3-cbc encryption password: 输入密码 Verifying - enter des-ede3-cbc encryption password: 再次输入 [[email protected] ~]# cd /tmp/ [[email protected] tmp]# ls issue_cipher yum.log [[email protected] tmp]# cat issue_cipher 查看加密后文件内容 U2FsdGVkX1+A3cLqRI09pTWDT6BhqierBK69evESmUcH9SOHUaA+0nw87hM5sDCT 2/PlBNgiqTMiiKelkoAyBw== 解密;openssl enc -d -des3 -a -salt -in /tmp/issue_cipher -out /mnt/issue [[email protected] ~]# openssl enc -d -des3 -a -salt -in /tmp/issue_cipher -out /mnt/issue enter des-ede3-cbc decryption password: 输入解密密码 [[email protected] ~]# cat /mnt/issue 查看解密后的内容 CentOS release 6.5 (Final) Kernel \r on an \m 用户认证;公钥加密,私钥解密
数字签名;私钥加密,公钥解密
3)、数字证书的证书格式(x509);
公钥和有效期;
持有者的个人身份信息;
证书的使用方式;
证书发放机构的信息;
验证CA的数字签名是否合法;
4)、基于openssl生成私有CA证书;
实验环境;Server,172.16.34.200
Client, 172.16.34.2
1,server端先生成密钥对; [[email protected] CA]# (umask 077; openssl genrsa -out private/cakey.pem 2048) Generating RSA private key, 2048 bit long modulus .....................................................................................................................+++ ......+++ e is 65537 (0x10001) 2、server完成自签证书;
3、创建需要的文件; [[email protected] CA]# touch index.txt serial crlnumber [[email protected] CA]# ls cacert.pem certs crl crlnumber index.txt newcerts private serial [[email protected] CA]# echo 1 > serial [[email protected] CA]# cat serial 1 [[email protected] CA]# 4、 client实现证书申请;
在主机上生成密钥,保存至应用此证书的服务的配置文件目录下; mkdir /etc/httpd/ssl cd /etc/httpd/ssl [[email protected] ssl]# (umask 077; openssl genrsa -out httpd.key 1024) Generating RSA private key, 1024 bit long modulus .++++++ ........++++++ e is 65537 (0x10001) [[email protected]lhost ssl]# ls httpd.key [[email protected] ssl]# 5、生成证书签署请求:
[[email protected] ssl]# openssl req -new -key httpd.key -out httpd.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:BJ Locality Name (eg, city) [Default City]:BJ Organization Name (eg, company) [Default Company Ltd]:Ouyang Organizational Unit Name (eg, section) []:linux Common Name (eg, your name or your server's hostname) []:ca.ouyang.com Email Address []:[email protected] Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:RedHat An optional company name []:redhat (Client端所填的信息要与服务器一致)
6、Clientc端将请求文件发往Server端;
scp httpd.csr 172.16.34.200:/tmp
7、CA签署Client发来的证书申请;
openssl ca -in /tmp/httpd.csr -out /tmp/httpd.csr -days 3655
8、签署完全后将证书发回申请者;
scp httpd.crt 172.16.34.20:/etc/httpd/ssl 9、吊销证书;吊销证书要到Server端;
openssl ca -revoke /tmp/httpd.crt
边栏推荐
- MySQL:SQL概述及数据库系统介绍 | 黑马程序员
- Solve the problems of Devops landing in complex environment with various tools with full stack and full function solutions
- CentOS - enable / disable Oracle
- C file pointer
- QT qstringlist usage
- Halcon knowledge: check the measurement objects [1]
- Peking University ACM problems 1002:487-3279
- 微信小程序怎么实现圆心进度条
- Is the project manager a leader? Can you criticize and blame members?
- 浅谈代码语言的魅力
猜你喜欢

Study on lumiprobe modified triphosphate biotin-11-utp

Wechat applet development practice cloud music

obsidian配合hugo的使用,让markdown本地编辑软件与在线化无缝衔接

【数字IC应届生职业规划】Chap.1 IC行业产业链概述及代表企业大厂汇总

Lumiprobe染料 NHS 酯丨BDP FL NHS 酯研究

偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的

Go语学习笔记 - gorm使用 - 数据库配置、表新增 | Web框架Gin(七)

Lumiprobe nucleic acid quantitative qudye dsDNA br detection kit

树基本概念

MFC界面库BCGControlBar v33.0 - 桌面警报窗口、网格控件升级等
随机推荐
CentOS - enable / disable Oracle
The newly born robot dog can walk by himself after rolling for an hour. The latest achievement of Wu Enda's first disciple
uniapp怎么上传二进制图片
Is it safe to open an account for online stock trading!?
BioVendor sRAGE Elisa试剂盒测试原理和注意事项
Lumiprobe protein quantitation - qudye Protein Quantitation Kit
二叉查找树(一) - 概念与C语言实现
Peking University ACM problems 1001:exposition
Playwright - scroll bar operation
How do I get the largest K massive data
Go语学习笔记 - gorm使用 - 数据库配置、表新增 | Web框架Gin(七)
docker安装mysql
Summary of PHP file upload (garbled code, move failure, permission, display picture)
北京大学ACM Problems 1000:A+B Problem
报错FileSystemException: /datas/nodes/0/indices/gtTXk-hnTgKhAcm-8n60Jw/1/index/.es_temp_file:结构需要清理
Lumiprobe生物素亚磷酰胺(羟脯氨酸)说明书
Testing principle and precautions of biovendor rage ELISA Kit
C file pointer
【数字IC应届生职业规划】Chap.1 IC行业产业链概述及代表企业大厂汇总
jfinal中如何使用过滤器监控Druid监听SQL执行?