长沙北大青鸟作者:科泰校区
不知道大家用过没用过 GnuPG 。GnuPG是GNU提供的用于安全通信和数据保存的工具。它可以用来对数据进行加密,也可以产生数字签名。在工具包中还包括了一个高级密钥管理工 具。(注意,GnuPG不和PGP2兼容,因为PGP2采用了有版权限制的加密算法)GnuPG使用的缺省算法是DSA和ElGamal;同步 (Symmetric)算法是:3DES、Blowfish、CAST5和Twofish;摘要算法是:MD5、RIPEMD160和SHA1。由于是 GPL版权所以大家可以安心使用
LINUX下安装:
1.下载:
在 http://www.gnupg.org/可找到下载文件并有最新消息或直接用下面路径下载
ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-1.0.6.tar.gz
MD5 checksums:
7c319a9e5e70ad9bc3bf0d7b5008a508 gnupg-1.0.6.tar.gz
71ae7d725776688c2e095d9672f38e61 gnupg-1.0.5-1.0.6.diff.gz
2.解压:
$tar xvzf gnupg-1.0.6.tar.gz
3.安装:
$cd gnupg-1.0.6
$./configure
默认安装目录是 /usr/local/bin 可以自己定制加入 --prefix=/dir
$make
$make install
Windows 下安装:
1. 解开压缩包最好在C:Gnupg目录(或是你喜欢的目录)
2. 如果你是用的C:Gnupg在注册表中加入下面的键HKEY_CURRENT_USERSoftwareGNUGnuPGHomeDir值等于C:Gnupg
3. 在运行或命令行模式下敲入gpg看是否运行.(建议在环境变量中加入路径,这样可以在任何目录运行gpg了)
使用方法 创建密钥对:
$gpg --gen-key
Please select what kind of key you want: 加密方式
(1) DSA and ElGamal (default)
(2) DSA (sign only)
(4) ElGamal (sign and encrypt)
Your selection? 1
DSA keypair will have 1024 bits. 密钥长度我觉的1024就可以了
About to generate a new ELG-E keypair. 如果你对加密有要求那就选2048
minimum keysize is 768 bits
default keysize is 1024 bits
highest suggested keysize is 2048 bits
What keysize do you want? (1024) 2048
Do you really need such a large keysize? y
Requested keysize is 2048 bits
Please specify how long the key should be valid. 生命期0为无限
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 key; the software constructs the user id
from Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) "
Real name: ricktan 填写用户信息
Email address: ricktan@sina.com.cn
Comment: GPG test!
You selected this USER-ID:
"ricktan (GPG test!) "
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.
Enter passphrase: 验证密码加解密是用
Repeat passphrase:
We need to generate a lot of random bytes. It is a good idea to perform
some other action (work in another window, move the mouse, utilize the
network and the disks) during the prime generation; this gives the random
number generator a better chance to gain enough entropy.
这样密钥对就生成了。我们可以自行对照PGP产生钥匙对的方式,简单说明其它指令的使用方式,而指令其中的可以键入user ID的某些部份即可,例如user ID是ricktan , 那么可以键入ricktan或sina等。
gpg --export [--armor] # outfile 取出的公开钥匙至 outfile中。
gpg --import [keyfile] 将公开钥匙[keyfile]加入钥匙环中。
gpg -k 列印出公开钥匙。
gpg -e -r file 加密file至binary档file.gpg中。
gpg -e -r --armor file 加密file至ASCII档file.asc中。
gpg -s file 加签file至binary档file.gpg中。
gpg -s --armor file 加签file至ASCII档file.asc中。
gpg -se -r file 加密加签file至binary档file.gpg中。
gpg -se -r [-armor] file 加密加签file至ASCII档file.asc中。
gpg -v file 解密file。
例:
加密文件test.doc
gpg -e -r ricktan test.doc
You need a passphrase to unlock the secret key for
user: "ricktan (GPG test!) "
1024-bit DSA key, ID 6541D744, created 2001-10-12
Enter passphrase:
会生成test.gpg文件删掉test.doc文件加密完成.
解开文件:
gpg -v test.gpg
还有一个重要的事一定要删掉加密后的原始文件,要不就和没加密一样了:)这样加密后基本上是无法破解的所以密钥一定不能丢.对有的系统要求有比较大的随机数,windows版没有这个问题.要是不能生成密钥对成就将这个选项在编译前
关掉 --enable-static-rnd=none
该选项内容如下:
--enable-static-rnd= Force the use of the random byte gathering
module . Default is either to use /dev/random
or the standard Uix module. Value for name:
egd - Use the module which accesses the
Entropy Gathering Daemon. See the webpages
for more information about it.
unix - Use the standard Unix module which does not
have a very good performance.
linux - Use the module which accesses /dev/random.
This is the first choice and the default one
for GNU/Linux or *BSD.
none - Do not linkl any module in but rely on
a dynmically loaded modules.