数据加密方式 | 形貌 | 主要解决的问题 | 常用算法 |
对称加密 | 指数据加密息争密使用相同的密钥 | 数据的机密性 | DES,AES |
非对称加密 | 也叫公钥加密,指数据加密息争密使用不同的密钥-密钥对 | 身份验证 | DSA,RSA |
单向加密 | 指只能加密数据,而不能解密数据 | 数据的完备性 | MD5,SHA系列算法 |
1 2 3 4 | 网站此时利用普通常见算法,针对暗码加密,基本保证数据再传输时间,不是明文 但是黑客大概会有一个庞大的算法本,里面记载了常见的暗码和加密后的密文,一一对应,然后可以利用步调大量计算,反解出明文暗码 撞库是黑客通过网络互联网已泄漏的用户和暗码信息,天生对应的字典表,尝试批量登陆其他网站后,得到一系列可以登录的用户。 很多用户在不同网站使用的是相同的帐号暗码,因此黑客可以通过获取用户在A网站的账户从而尝试登录B网址,这就可以理解为撞库攻击。 |
1 2 3 4 5 6 7 | 对称加密算法,如其名,就是使用同一个秘钥举行加密息争密。 优点是速度较快,适合对数据量比较大的数据举行加密。 缺点是密钥的保存方式须要保证,一旦加密大概解密的哪一方泄漏了密钥,都会导致信息的泄漏。 常用的对称加密算法有 ![]() |
1 2 3 4 5 6 | 简朴理解,比喻关系 公钥---锁 私钥---开锁钥匙 私钥只能由一方安全保管,不能外泄,而公钥则可以发给任何请求它的人。非对称加密使用这对密钥中的一个举行加密,而解密则须要另一个密钥。 好比,你向银行请求公钥,银行将公钥发给你,你使用公钥对消息加密,那么只有私钥的持有人--银行才能对你的消息解密。与对称加密不同的是,银行不须要将私钥通过网络发送出去,因此安全性大大提高。 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 虽然非对称加密很安全,但是和对称加密比起来,它非常的慢,所以我们还是要用对称加密来传送消息,但对称加密所使用的密钥我们可以通过非对称加密的方式发送出去。为了解释这个过程,请看下面的例子: 1.使用对称加密,速度快 2.使用非对称加密的方式,针对第一步的秘钥加密传输 (1) 超哥须要在银行的网站做一笔生意业务,他的浏览器起首天生了一个随机数作为对称密钥。 (2) 超哥的浏览器向银行的网站请求公钥(非对称加密的公钥~~)。 (3) 银行将公钥发送给超哥。 (4) 超哥的浏览器使用银行的公钥将自己的对称密钥加密(这里是重点,已经是【对称加密+非对称加密】)。 (5) 超哥的浏览器将加密后的对称密钥发送给银行。 (6) 银利用用私钥解密得到超哥浏览器的对称密钥。 (7) 超哥与银行可以使用对称密钥来对沟通的内容举行加密与解密了。 |
1 2 3 4 5 | 1.对称加密方式,加密解密使用同样的密钥,速度较快,但是密钥须要在网络中传输,因此大概被截获,不安全 2.非对称加密,使用一对密钥,公钥,私钥,因此安全性很高,但是加密息争密速度很慢 3.常用的方式是,结合两种加密方式,效率与安全性都有又了保障。 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # 查抄版本 [root@chaogelinux ~]# openssl version OpenSSL 1.0.2k-fips 26 Jan 2017 # 配置文件 [root@chaogelinux ~]# cat /etc/pki/tls/openssl.cnf #获取openssl下令操作 [root@chaogelinux ~]# openssl -? openssl:Error: '-?' is an invalid command. # 标准下令 Standard commands asn1parse ca ciphers cms crl crl2pkcs7 dgst dh dhparam dsa dsaparam ec ... # 信息摘要下令,单向加密下令 Message Digest commands (see the `dgst' command for more details) md2 md4 md5 rmd160 sha sha1 # 加密下令 Cipher commands (see the `enc' command for more details) aes-128-cbc aes-128-ecb aes-192-cbc aes-192-ecb aes-256-cbc aes-256-ecb base64 bf bf-cbc bf-cfb bf-ecb bf-ofb # 测试机器对openssl支持的加密算法举行速度测试,检测服务器性能 openssl speed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 语法 openssl enc -加密算法 -in filename -out filename # 对文件加密 [root@chaogelinux ~]# cat my.pwd yu:123 [root@chaogelinux ~]# [root@chaogelinux ~]# # 输入暗码后加密乐成,超哥这里是888888 [root@chaogelinux ~]# openssl enc -des3 -salt -a -in my.pwd -out my.pwd.des3 enter des-ede3-cbc encryption password: Verifying - enter des-ede3-cbc encryption password: #解密文件 [root@chaogelinux ~]# cat my.pwd.des3 U2FsdGVkX19ZDOFtbdZz3QNu+bxm3DKd [root@chaogelinux ~]# # 输入暗码后,解密文件 [root@chaogelinux ~]# openssl enc -des3 -d -salt -a -in my.pwd.des3 -out my.pwd.src enter des-ede3-cbc decryption password: [root@chaogelinux ~]# [root@chaogelinux ~]# cat my.pwd.src yu:123 参数解释: enc openssl把浩繁的对称加密算法,同一集成在了enc指令,用法是 enc -算法名 -des3 指定算法 -d 指定解密 -e 指定加密 -salt 暗码加盐,防止暗码被破解 -a 基于base64位编码,可选参数 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # 指定私钥长度1024,并且将天生的私钥信息保存在文件里,且利用小括号功能,修改子shell的umask [root@chaogelinux ssl_cert]# (umask 077;openssl genrsa -out server1024.key 1024) Generating RSA private key, 1024 bit long modulus ..........++++++ ...................++++++ e is 65537 (0x10001) # 读取私钥文件,选择非对称加密算法rsa,天生公钥,写入到文件中 [root@chaogelinux ssl_cert]# openssl rsa -in server1024.key -pubout -out server1024.key.pub # 查抄文件 [root@chaogelinux ssl_cert]# ls server1024.key server1024.key.pub # 天生自签的证书 [root@chaogelinux ssl_cert]# openssl req -new -x509 -key server1024.key -out server.crt -days 365 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]:chaoge Organizational Unit Name (eg, section) []:it Common Name (eg, your name or your server's hostname) []:pythonav.cn |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | 1.创建Nginx须要的证书文件 确保机器安装了openssl和openssl-devel,创建证书 yum install openssl openssl-devel -y 2.确保nginx支持了ssl模块,检察nginx编译信息即可 nginx -V 3.模拟证书颁发机构CA创建证书 进入nginx安装目录,便于管理证书 [root@chaogelinux ~]# cd /opt/ngx112/ [root@chaogelinux ngx112]# mkdir key [root@chaogelinux ngx112]# cd key/ # 天生私钥文件,利用字shell降低文件权限 [root@chaogelinux key]# (umask 077;openssl genrsa -out server1024.key 1024) Generating RSA private key, 1024 bit long modulus .++++++ ...++++++ e is 65537 (0x10001) # 自己签发证书,crt证书扩展名 [root@chaogelinux key]# openssl req -new -x509 -key server1024.key -out server.crt -days 365 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]:chaoge Organizational Unit Name (eg, section) []:it Common Name (eg, your name or your server's hostname) []:pythonav.cn Email Address []:yc_uuu@163.com # 向机构申请证书,我们这里天生的是证书请求文件,而不是直接天生证书了,运维发送该文件给机构,请求合法证书 [root@chaogelinux key]# openssl req -new -key server1024.key -out server.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]:chaoge Organizational Unit Name (eg, section) []:it Common Name (eg, your name or your server's hostname) []:pythonav.cn Email Address []:yc_uuu@163.com # 针对这个请求文件,做一个加密处理,告知办法机构,可以用这个暗码解密,了解公司信息,也可以直接回车不写暗码 Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: # 一般这个证书颁发,须要比及一周内的时间,因此我们直接使用本地的自己签发的证书即可,举行训练 4.配置Nginx,加载私钥,证书 修改nginx.conf,添加 include extra/443.conf; # 创建https配置文件 vim 443.conf 写入 [root@web01 extra]# cat 443.conf server { server_name _; listen 443 ssl; ssl_certificate /opt/nginx/key/server.crt; ssl_certificate_key /opt/nginx/key/server1024.key; charset utf-8; location / { root html; index index.html index.htm; } } ~ # 修改80端口假造主机,举行请求转发给443 } server { listen 80; server_name www.chaoge.com; charset utf-8; rewrite ^(.*)$ https://$host$1 permanent; location / { root html; index index.html index.htm; } } include extra/443.conf; } # 检测语法,重启nginx [root@web01 extra]# nginx -t nginx: the configuration file /opt/nginx-1.16.0//conf/nginx.conf syntax is ok nginx: configuration file /opt/nginx-1.16.0//conf/nginx.conf test is successful |
欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/) | Powered by Discuz! X3.4 |