首先安装GPG
sudo apt install gnupg
gpg --gen-key
Real name: 输入用户名
Email address: 输入邮箱
Change (N)ame, (E)mail, or (O)kay/(Q)uit? O
最后查看
gpg --list-keys
PGP是一种加密软件。
PGP的开创者是 Philip R. Zimmermann ,这个技术牛人有一个以自己命字为域名的网站介绍自己: www.philzimmermann.com
在1991年他在因特网上发布了这个软件的第一个版本,他把这加密软件的名字叫 Pretty Good Privacy 简称PGP
然后他创办了PGP 公司免费提供该软件并且是开源的,后来公司卖给了 Network Associates(美国网络联盟公司), 从2010年起PGP软件已被 Symantec (赛门铁克,诺顿的产商) 收购,并集成在他的产品这中,不再提供免费的PGP加密软件,不再开源。
现在获取PGP软件的方式就是从Symantec处购买。
OpenPGP 是一种加密的标准,它不是软件。
这个加密标准由IETF(Internet Engineering Task Force)制定, 标准原文见 RFC 4880 ,这个OpenPGP的标准,就是由PGP衍生而来,可以这么说Philip R. Zimmermann 的PGP软件为 OpenPGP标准做出了巨大贡献。
GPG 是一种开源免费的加密软件。
GPG 也叫 GnuPG 它是由Gnu组织根据 OpenPGP 标准( RFC 4880 )而编写的加密软件。从理论上来说,可以替代 PGP 软件。
先举个简单的例子:
Michael用 PGP 软件加密了一个文件传给了 Ann , 那么Ann可以使用 PGP 软件解密,也可以选择使用 GPG 软件解密。
反之亦然,Ann 用 GPG 加密给 hooyes 的文件,Michael可以用 PGP 进行解密。
当然,上面的例子中,加密、解密这是有前提的,除了拥有软件之外,Michael与 Ann 互相交换了密钥对中的公钥,并使用了对方的公钥和自己的私钥进行加密和签名,这也说明了 GPG 与 PGP 都识别对方软件的公私钥,也识别了签名。
这一篇暂时写这么多了,已介绍了PGP,OpenGPG,GPG 的定义和三者之间的关系。
Philip R. Zimmermann 简介: http://www.philzimmermann.com/ZH/background/index.html
PGP软件: http://www.pgp.com
OpenPGP官网: http://www.openpgp.org
GPG官网: http://www.gnupg.org
GPG加密和解密随着网络与计算机技术的发展,数据存储与数据交换的安全性已经变得越来越重要,加密技术已经很早就用于数据存储和数据交换。为了确保网络数据交换时的双方身份的正确性,签证体系也已经成熟。GPG就是用来加密数据与制作证书的一套工具,它是一个完全免费、源代码公开,并且与PGP完全兼容的软件产品。GPG软件作为用于加密和数字签名的开放源码工具,许多Linux发行版本都自带了该软件。
下面,让我们一起来看看,gpg如何加密和解密的吧。
创建密钥
gpg --gen-key
你要求输入一下内容,这些内容,基本英文,还是很好明白
root@g140:~# gpg --gen-key
gpg (GnuPG) 1.4.11Copyright (C) 2010 Free SoftwareFoundation, Inc.
This is free software: you are free to change andredistribute it.
There is NO WARRANTY, to the extent permitted by law.
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf'created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are notyet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection?
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.
0 = key does not expire
= key expires in n days
w = key expires in n weeks
m = key expires in n months
y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y
You need a user ID to identify your keythe softwareconstructs the user ID
from the Real Name, Comment and Email Address in thisform:
"Heinrich Heine (Der Dichter) "
Real name: chenshake
Email address: shake.chen@gmail.com
Comment:
You selectedthis USER-ID:
"chenshake "
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.
We need to generate a lot of random bytes. It is a goodidea to perform
some other action (type on the keyboard, move the mouse,utilize the
disks) during the prime generationthis gives the randomnumber
generator a better chance to gain enough entropy.
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key AEAA16F3 marked as ultimately trusted
public and secret key created and signed.
gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGPtrust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m,0f, 1u
pub 2048R/AEAA16F3 2013-10-21
Key fingerprint = B93B 05F8 9D63 5464 6DEE 6A08 EB9E D2BBAEAA 16F3
uid chenshake
sub 2048R/02B4038D 2013-10-21
就是上面这个过程
在这个生成密钥的过程中,有个步骤很重要,就是生成内存随机数,命令如下:
ddif=/dev/zero of=test.dbf bs=9000 count=1000k .直到生成key为止。
查看私钥
# gpg -k
/root/.gnupg/pubring.gpg
------------------------
pub 2048R/AEAA16F3 2013-10-21
uid chenshake
sub 2048R/02B4038D 2013-10-21
查看公钥
# gpg --list-keys
/root/.gnupg/pubring.gpg
------------------------
pub 2048R/AEAA16F3 2013-10-21
uid chenshake
sub 2048R/02B4038D 2013-10-21
导出公钥
gpg -o chenshake.gpg -a --export chenshake
其中chenshake为用户ID
chenshake.gpg为导出的公钥文件
导出私钥
gpg -o chenshake-private.gpg --export-secret-keyschenshake
导入秘钥
公钥和私钥的导入,都是一样。
gpg --import filename
公钥
(另外一台机器)
当然你需要通过scp把公钥复制到远程的机器
# gpg --import chenshake.gpg
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf'created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are notyet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key AEAA16F3: public key "chenshake "imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
你也可以查看到导入的公钥
# gpg --list-keys
/root/.gnupg/pubring.gpg
------------------------
pub 2048R/AEAA16F3 2013-10-21
uid chenshake
sub 2048R/02B4038D 2013-10-21
公钥加密
一个文件,我这里是加密cobbler.ks 这个文件,加密后是 cobbler.ks.gpg文件,需要私钥才能查看。
# gpg -o cobbler.ks.gpg -er chenshake cobbler.ks
gpg: 02B4038D: There is no assurance this key belongs tothe named user
pub 2048R/02B4038D 2013-10-21 chenshake
Primary key fingerprint: B93B 05F8 9D63 5464 6DEE 6A08EB9E D2BB AEAA 16F3
Subkey fingerprint: FCCA 50DD C98D 644E 00FB 804C 4CD29544 02B4 038D
It is NOT certain that the key belongs to the personnamed
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
私钥解密
私钥查看 cobbler.ks.gpg
# gpg -o cobbler.ks -d cobbler.ks.gpg
You need a passphrase to unlock the secret key for
user: "chenshake "
2048-bit RSA key, ID 02B4038D, created 2013-10-21 (mainkey ID AEAA16F3)
gpg: gpg-agent is not available in this session
gpg: encrypted with 2048-bit RSA key, ID 02B4038D,created 2013-10-21
"chenshake "
需要你输入你当初创建秘钥的时候设置的那个密码。这个时候,你就可以查看到加密的文件。
【编辑推荐】
如何对LUKS加密的磁盘/分区执行远程增量备份?
找回MD5加密的密码及MD5加密数据库中数据
对称加密之AES及压缩加密解密解压综合实战
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)