对称加密算法
-c:使用对称加密
-s:签名
1
2
3
4
5
|
[root@localhost tmp]
# gpg -c etc-2015-09-08.tar.bz2
[root@localhost tmp]
# ls
etc initramfs-3.10.0-123.el7.x86_64.img systemd-private-VeulCa
etc-2015-09-08.
tar
.bz2
ssh
-gerghZxz75YC vmlinuz-3.10.0-123.el7.x86_64
etc-2015-09-08.
tar
.bz2.gpg systemd-private-3nSRGS vmware-root
|
解密
1
|
[root@localhost tmp]
# gpg text1.gpg
|
公钥加密 私钥解密:数字证书 可以保证数据机密性
私钥加密 公钥解密:数字签名 可以身份验证
1
|
[root@localhost tmp]
# gpg --gen-key #生成密钥对
|
查看公钥
1
2
3
4
5
6
|
[root@localhost Desktop]
# gpg --list-key
/root/
.gnupg
/pubring
.gpg
------------------------
pub 1024R
/FC2F0004
2015-09-17
uid chomper
sub 1024R
/BE6179F8
2015-09-17
|
查看私钥
1
2
3
4
5
6
|
[root@localhost Desktop]
# gpg -K
/root/
.gnupg
/secring
.gpg
------------------------
sec 1024R
/FC2F0004
2015-09-17
uid chomper
ssb 1024R
/BE6179F8
2015-09-17
|
导出公钥
-a:以ASCII的方式输出
1
|
[root@localhost ~]
# gpg --export -a > rhel7.pub
|
导入公钥
1
2
3
4
|
[root@localhost ~]
# gpg --import centos6.5.pub
gpg: key 7AABAD23: public key
"centos6.5"
imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
|
使用centos6.5这个公钥加密inter文件
-e:加密
-r:用哪个钥匙加密
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@localhost ~]
# gpg -ear centos6.5 inter
gpg: 61ED0E54: There is no assurance this key belongs to the named user
pub 1024R
/61ED0E54
2015-09-17 centos6.5
Primary key fingerprint: 63ED 8DF3 4D82 593C 8AB2 8559 FB1A 90AE 7AAB AD23
Subkey fingerprint: CC9F DD39 980A B63E 9592 003E D864 AB9C 61ED 0E54
It is NOT certain that the key belongs to the person named
in
the user ID. If you *really* know what you are doing,
you may answer the next question with
yes
.
Use this key anyway? (y
/N
) y
[root@localhost ~]
# ls
anaconda-ks.cfg Desktop Downloads hostnamz~ inter.asc Music Public Templates
centos6.5.pub Documents
hostname
~ inter Mail Pictures rhel7.pub Videos
|
使用centos6.5的私钥来解密inter.asc
1
2
3
4
5
6
7
8
9
|
[root@centos6 ~]
# gpg inter.asc
You need a passphrase to unlock the secret key
for
user:
"centos6.5"
1024-bit RSA key, ID 61ED0E54, created 2015-09-17 (main key ID 7AABAD23)
can
't connect to `/root/.gnupg/S.gpg-agent'
: No such
file
or directory
gpg: encrypted with 1024-bit RSA key, ID 61ED0E54, created 2015-09-17
"centos6.5"
|
签名:-s
1
|
[root@localhost ~]
# gpg -s inter
|
生成inter.gpg
gpg -sea #:既签名又加密
服务端把自己的公钥给CA,CA用自己的私钥对服务端的公钥签名(证书)。
客户端用CA的公钥解密服务端发过来的证书,获得服务端的公钥。
密钥交换(IKE):双方如何协商安全保密的生成密钥
双方使用相同的密钥,应该属于对称加密
非对称加密速度太慢,一般不用于加密数据本身,常用于身份验证,
还有保证数据的完整性,确认有没被篡改
证书:
对服务器的名字、IP、公钥等信息生成特征码,然后用CA的私钥对特征码加密,
这些服务器的信息加上加密的特征码整个组合成一个证书。
用户访问服务器B,首先需要验证B的身份,B先把自己的证书发给用户,用户用CA的公钥对证书进行解密验证,并获得B的公钥,进而验证B的身份。
CRL:证书吊销列表
对称加密:
DES:Data Encrption Standard 56bit
3DES
AES:Advanced AES192 AES256 AES512
单向加密:定长输出
MD4
MD5:128bit
SHA1
SHA192 SHA256 SHA384
CRC-32:校验码的计算机制,不是加密
非对称加密:
加密、签名
RSA:加密、签名
DSA:签名
工具:
openssl
gpg
本文转自 chomperwu 51CTO博客,原文链接:http://blog.51cto.com/chomper/1695792,如需转载请自行联系原作者