SA Blog --系统管理员的博客生涯

书写自己的系统管理博客生涯
posts(330) comments(254) trackbacks(0)
  • IT博客
  • 联系
  • RSS 2.0 Feed 聚合
  • 管理

常用链接

  • 我的随笔
  • 我的评论
  • 我参与的随笔

留言簿

  • 给我留言
  • 查看公开留言
  • 查看私人留言

随笔分类(395)

  • *UNIX系统(148)
  • Cloud(3)
  • Moive
  • Music(1)
  • OpenStack(7)
  • openstack
  • Wiki(1)
  • Windows系统(32)
  • 其他(33)
  • 娱乐
  • 存储相关(22)
  • 存储网络(10)
  • 常用工具下载(25)
  • 数据库应用技术(53)
  • 网络技术(41)
  • 英语
  • 虚拟化(19)

随笔档案(330)

  • 2020年9月 (1)
  • 2020年8月 (1)
  • 2020年7月 (8)
  • 2020年4月 (1)
  • 2020年2月 (1)
  • 2020年1月 (1)
  • 2019年9月 (2)
  • 2019年4月 (1)
  • 2016年1月 (1)
  • 2015年12月 (1)
  • 2015年7月 (4)
  • 2015年5月 (2)
  • 2014年3月 (2)
  • 2014年1月 (1)
  • 2013年12月 (1)
  • 2013年3月 (5)
  • 2013年2月 (4)
  • 2012年12月 (1)
  • 2012年11月 (2)
  • 2012年9月 (2)
  • 2012年8月 (1)
  • 2012年6月 (1)
  • 2012年5月 (1)
  • 2012年1月 (1)
  • 2011年12月 (2)
  • 2011年10月 (1)
  • 2011年9月 (3)
  • 2011年8月 (1)
  • 2011年7月 (5)
  • 2011年6月 (3)
  • 2011年5月 (5)
  • 2011年4月 (2)
  • 2011年3月 (2)
  • 2011年2月 (1)
  • 2011年1月 (5)
  • 2010年12月 (1)
  • 2010年11月 (4)
  • 2010年9月 (13)
  • 2010年8月 (4)
  • 2010年7月 (5)
  • 2010年6月 (5)
  • 2010年5月 (13)
  • 2010年4月 (10)
  • 2010年3月 (5)
  • 2010年2月 (1)
  • 2010年1月 (9)
  • 2009年12月 (5)
  • 2009年11月 (5)
  • 2009年10月 (1)
  • 2009年9月 (3)
  • 2009年8月 (2)
  • 2009年7月 (6)
  • 2009年6月 (3)
  • 2009年5月 (2)
  • 2009年4月 (1)
  • 2009年3月 (2)
  • 2009年2月 (3)
  • 2008年12月 (3)
  • 2008年11月 (1)
  • 2008年10月 (9)
  • 2008年9月 (5)
  • 2008年8月 (3)
  • 2008年7月 (1)
  • 2008年6月 (1)
  • 2008年5月 (2)
  • 2008年4月 (1)
  • 2008年3月 (1)
  • 2008年2月 (3)
  • 2008年1月 (1)
  • 2007年12月 (5)
  • 2007年11月 (1)
  • 2007年10月 (6)
  • 2007年9月 (4)
  • 2007年8月 (4)
  • 2007年7月 (34)
  • 2007年6月 (1)
  • 2007年4月 (2)
  • 2007年3月 (1)
  • 2007年2月 (1)
  • 2006年11月 (1)
  • 2006年9月 (4)
  • 2006年8月 (4)
  • 2006年7月 (1)
  • 2006年6月 (10)
  • 2006年5月 (3)
  • 2006年4月 (14)
  • 2006年2月 (6)
  • 2006年1月 (6)
  • 2005年12月 (12)

收藏夹(5)

  • Other(5)

IT技术

  • MSDN 库(中文)
  • 欢迎使用 MSDN 库(中文),MSDN 库为使用 Microsoft® 工具、产品、技术和服务的开发人员提供必不可少的信息资源。MSDN 库包含操作方法和参考文档、示例代码、技术文章和其他内容。请浏览目录或使用搜索功能来查找所需内容。

健康

  • 体检咨询
  • 北京体检 体检咨询
  • 足医生
  • 足医生

友情链接

  • TestLink中文论坛
  • Testlink 中文论坛
  • 备案专题
  • 备案专题
  • 微软大中华区安全博客
  • 微软大中华区安全博客

存储技术

  • doit存储
  • doit 存储,存储热门论坛
  • ITPUB
  • Oracle DBA 热门中文社区
  • TechTarget IT专家网
  • 蓝德科技

网络技术

  • ChinaUnix 中文社区
  • ChinaUnix 热门中文社区

搜索

  •  

最新评论

  • 1. re: 吐槽一下阿里系软件,就是天天的升级???
  • 评论内容较长,点击标题查看
  • --David
  • 2. re: Symantec Backup exec system recovery 2010(BESR 2010)故障汇总
  • 评论内容较长,点击标题查看
  • --112
  • 3. re: OpenStack安装部署管理中常见问题解决方法(OpenStack-Lite-FAQ)
  • /home/stack/devstack/tools/worlddump.py -d /home/stack/logs
    求救这是什么问题啊。
  • --陈晓龙
  • 4. re: nokia 手机密码忘记后破解
  • nokia 2630,密码不见,恳请帮忙,谢谢
    串号:355219037959407
    lipolipo@gmail.com
  • --沈同学
  • 5. re: chroot 工具 jailkit 限制用户 活动范围 和 权限 _ 笔记
  • 是一个很好的工具嘛。感谢分享。
  • --少林功夫好

阅读排行榜

评论排行榜

View Post

Linux/Windows下的文件加密 GnuPG

Linux/Windows下的文件加密 GnuPG

作者:谭圣

最近本人忽然对加密感兴趣。研究了一下Linux下的文件加密。发现现在国内好像没什么人在用,是我们的保密意识太强了还是我们的秘密太少了或不 值得保密?少说废话了开始工作。

不知道大家用过没用过 GnuPG 。GnuPG是GNU提供的用于安全通信和数据保存的工具。它可以用来对数据进行加密,也可以产生数字签名。在工具包中还包括了一个高级密钥管理工 具。(注意,GnuPG不和PGP2兼容,因为PGP2采用了有版权限制的加密算法)GnuPG使用的缺省算法是DSA和ElGamal;同步 (Symmetric)算法是:3DES、Blowfish、CAST5和Twofish;摘要算法是:MD5、RIPEMD160和SHA1。由于是 GPL版权所以大家可以安心使用,更进一步的说明请参考http://www.d.shuttle.de/isil/gnupg。

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.



如果在使用上有问题,可以先参考gnupg-0.9.4/doc/FAQ
或
http://www.gnupg.org/faq.html
http://www.gnupg.org/docs-mls.html

posted on 2010-05-31 00:28 David 阅读(2194) 评论(5)  编辑 收藏 引用 所属分类: *UNIX系统

View Comments

# re: Linux/Windows下的文件加密 GnuPG[未登录]  回复  更多评论   


1. 生成和查看密钥

gpg --gen-key

查看生成的公钥

gpg --list-keys

查看、建立的私钥

gpg --list-secret-keys

2 加密解密文件

用公钥加密
gpg -ea -r xli@redhat.com /directory/filename

用私钥解密

gpg -d /directory/filename.asc > /directory/filename

3. 导出和导入公钥

gpg --export "xli@redhat.com" -o leonli_publickey.asc (-a 输出ascii格式)

gpg --import leonli_publickey.asc

导入他人公钥以后,一般需要用自己的私钥对导入的他人公钥进行签名,(使用 --sign-key 选项进行签名,签名的目的是证明您完全信任这个公钥的合法性。 ):

gpg --sign-key brian@worldcontrol.com

对公钥签名以后,可以使用下面命令来对公钥环中的公钥的签名进行检查:

gpg --check-sig

导入对方的公钥以后,就可以用对方的公钥来加密文件:

gpg -ea -r xli@redhat.com /directory/filename

4. 查看公钥指纹信息:

gpg --fingerprint xli@redhat.com

得到指纹以后,通过其他途径与公钥所有人确认(电话等)

5 发送公钥到互联网网站

gpg --keyserver subkeys.pgp.net --send-keys xli@redhat.com

发送到互联网网站以后,可以从服务器上查找(查找到以后,命令会提示是否要下载):

gpg --keyserver subkeys.pgp.net --search-keys xli@redhat.com

也可以直接从服务器上下载

gpg --recv-keys brian@worldcontrol.com

6 修改密钥
gpg --edit-key "Leon Li"

7 备份密钥
备份公钥:

gpg -o keyfilename --export KeyID
如果没有KeyID则是备份所有的公钥,-o表示输出到文件 keyfilename中,如果加上-a的参数则输出文本格式的信息,否则输出的是二进制格式信息。

备份私钥:

gpg -o keyfilename --export-secret-keys KeyID

如果没有KeyID则是备份所有的私钥,-o表示输出到文件keyfilename中,如果加上-a的参数则输出文本格式的信息,否则输出的是二进制格式信息。

在别的机器上可以通过

gpg --import filename

导入这些信息。

8 签名

进行签名:
gpg --output doc.sig --sign doc
签名以后得到的内容是二进制(在签名以前对源文件进行压缩,然后签名),签名得到的结果同时也就是被加密了的

给定一个签名的文档,你或者可以检查签名,或者可以检查签名并恢复原始文档。要检查签名使用 --verify 选项。要验证签名并提取文档使用 --decrypt选项。 输入要验证并恢复的签名文档,就可以输出恢复后的文档。
gpg --verify doc.sig
gpg --output doc --decrypt doc.sig

明文签名(clearsigned)文档

数字签名的一个普遍用途就是对usenet的帖子或是email消息进行签名。在这种情况下我们对文档进行签名但不希望压缩文档。选项 --clearsign 让文档封装在一个ASCII铠甲式的签名中,但并不改动文档。

alice% gpg --clearsign doc

分离签名

签名后的文档只有有限的用途。其他用户必须从签名版本中恢复原始文档,即使在明文签名文档中,签名后的文档必须编辑以恢复原始模样。因此,有第三种方法对文档进行签名,该方法创建一个可分离的签名,该签名是一个单独的文件。一个分离签名使用 --detach-sig选项来创建。

alice% gpg --output doc.sig --detach-sig doc

You need a passphrase to unlock the secret key for
user: "Alice (Judge) "
1024-bit DSA key, ID BB7576AC, created 1999-06-04

Enter passphrase:

要验证签名必须同时使用文档和分离签名。选项--verify可以用来检查签名。

blake% gpg --verify doc.sig doc
gpg: Signature made Fri Jun 4 12:38:46 1999 CDT using DSA key ID BB7576AC
gpg: Good signature from "Alice (Judge) "
2010-05-31 15:42 | david
# re: Linux/Windows下的文件加密 GnuPG  回复  更多评论   
一直使用gpgshell工具,命令行操作都没使用过了,都忘得差不多了,记录下常用操作命令:

导出私钥命令
#gpg –export-secret-keys -a -o kevin.asc

导出公钥命令:
#gpg -a –export twork@21cn.com >kevin.gpg

搜索subkeys.pgp.net服务器上的公钥:
#gpg –search-keys –keyserver subkeys.pgp.net twork@21cn.com

你能直接通过 GnuPG 导入密钥

gpg --keyserver subkeys.pgp.net --recv-keys B120107B

或搜索密钥

gpg --keyserver subkeys.pgp.net --search-keys B120107B

当你选择其中一个时,它将被加入你的密钥环(keyring)

上传公钥至subkey.pgp.net服务器:
#gpg –send-keys –keyserver subkeys.pgp.net twork@21cn.com

加数数据给king2789@163.com(注:-e加密,-a 使用ASCII,-c使用对称加密,-r选择接收人)
#gpg -e -a -c -r king2789@163.com aa.txt

解密数据(注:如果king2789@163.com连续5次输错自己的私钥密码,第5次时候可以使用对称密码解密)
#gpg -d aa.txt.gpg >aa.txt

管理GPG的工具有:gpgshell,当前版本3.72
下载地址:http://www.jumaros.de/rsoft/index.html

常用金钥服务器:http://subkeys.pgp.net
#gpg -h (帮助信息)
gpg (GnuPG) 1.4.9
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: C:/Documents and Settings/Chenkangle/Application Data/gnupg
支持的算法:
公钥:RSA, RSA-E, RSA-S, ELG-E, DSA
对称加密:3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH
散列:MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
压缩:不压缩, ZIP, ZLIB, BZIP2

语法:gpg [选项] [文件名]
签名、检查、加密或解密
默认的操作依输入数据而定

指令:

-s, –sign [文件名] 生成一份签名
–clearsign [文件名] 生成一份明文签名
-b, –detach-sign 生成一份分离的签名
-e, –encrypt 加密数据
-c, –symmetric 仅使用对称加密
-d, –decrypt 解密数据(默认)
–verify 验证签名
–list-keys 列出密钥
–list-sigs 列出密钥和签名
–check-sigs 列出并检查密钥签名
–fingerprint 列出密钥和指纹
-K, –list-secret-keys 列出私钥
–gen-key 生成一副新的密钥对
–delete-keys 从公钥钥匙环里删除密钥
–delete-secret-keys 从私钥钥匙环里删除密钥
–sign-key 为某把密钥添加签名
–lsign-key 为某把密钥添加本地签名
–edit-key 编辑某把密钥或为其添加签名
–gen-revoke 生成一份吊销证书
–export 导出密钥
–send-keys 把密钥导出到某个公钥服务器上
–recv-keys 从公钥服务器上导入密钥
–search-keys 在公钥服务器上搜寻密钥
–refresh-keys 从公钥服务器更新所有的本地密钥
–import 导入/合并密钥
–card-status 打印智能卡状态
–card-edit 更改智能卡上的数据
–change-pin 更改智能卡的 PIN
–update-trustdb 更新信任度数据库
–print-md 算法 [文件] 使用指定的散列算法打印报文散列值

选项:

-a, –armor 输出经 ASCII 封装
-r, –recipient 某甲 为收件者“某甲”加密
-u, –local-user 使用这个用户标识来签名或解密
-z N 设定压缩等级为 N (0 表示不压缩)
–textmode 使用标准的文本模式
-o, –output 指定输出文件
-v, –verbose 详细模式
-n, –dry-run 不做任何改变
-i, –interactive 覆盖前先询问
–openpgp 行为严格遵循 OpenPGP 定义
–pgp2 生成与 PGP 2.x 兼容的报文

(请参考在线说明以获得所有命令和选项的完整清单)

范例:

-se -r Bob [文件名] 为 Bob 这个收件人签名及加密
–clearsign [文件名] 做出明文签名
–detach-sign [文件名] 做出分离式签名
–list-keys [某甲] 显示密钥
–fingerprint [某甲] 显示指纹

请向 <gnupg-bugs@gnu.org> 报告程序缺陷。
请向 <i18n-zh@googlegroups.com> 反映简体中文翻译的问题。

我的GPG公钥:B120107B

可在subkeys.pgp.net下载:http://keys.nayr.net/pks/lookup?op=get&search=0×15E59411B120107B
2010-05-31 16:18 | pgp
# re: Linux/Windows下的文件加密 GnuPG  回复  更多评论   
otes for using GPG to encrypt and decrypt backup files
GPG allows you to use public-private key encryption to encrypt
and decrypt files on Windows and Linux. The benefit of public-private
key encryption is that you can keep your public key out in
the open, and use it from anywhere to encrypt files. Once
encrypted with the public key, those files can only be decrypted
with the private key. The idea is to keep the private key
someplace safe, like on a CDROM in a bank vault, and then you can
keep the encrypted backup files and public key just about anywhere.
Better yet, you can send the encrypted backup files over easy-to-use,
unencrypted network protocols, like FTP and HTTP.

In a simple, scheduled Perl script, I can create a backup of my websites,
encrypt them, and then transfer them by anonymous FTP to my home computer.
Similarly, I can encrypt important files on my home computer and store
them safely on third-party servers. The notes below outline the commands
that are needed to perform the necessary operations.

GPG requires a home directory to store its keys.
In Linux, it uses HOME/.gnupg
In Windows, it uses what you specify in the registry keys,
which by default is c:\GnuPG

Keys are stored in files called "key rings".
The secring.gpg file is the key ring that stores secret keys.
The pubring.gpg file is the key ring that stores public keys.

Keys in the key rings are referred to by the name, or partial name.
e.g. to refer to the key of "Shailesh N. Humbad",
you can use "Shailesh" as the name.

To create a new public/private key pair, run:
gpg --gen-key
and follow the prompts.

To list public keys, run:
gpg --list-keys

To list private or secret keys, run:
gpg --list-secret-keys

To export a public key to an ascii text file, run:
gpg -a --export NAME > yourpublickey.gpg

To export a private (or secret) key to an ascii text file, run:
gpg -a --export-secret-keys NAME > yourprivatekey.gpg

To delete a public key from the local key ring:
gpg --delete-keys NAME

To delete a secret key from the local key ring:
gpg --delete-secret-key NAME

To encrypt a file, use:
gpg -r NAME --output OUTFILE.gpg --encrypt INFILE

To decrypt a file, use:
gpg -r NAME --output OUTFILE --decrypt INFILE.gpg

If you leave out the "-r" option, it will prompt you for the
name of the user whose key should be used.
Decrypting a file requires that you have the secret key in the local
key ring, and it will prompt you for the passphrase to access the secret key.


2010-06-03 11:03 | aa
# re: Linux/Windows下的文件加密 GnuPG  回复  更多评论   
The aim of this document is to explain a little bit the meaning of the table that you obtain when you issue the command to update the trust database of your GnuPG installation.

For instance, let's suppose that the command produces the following output:

user@host:~$ gpg --update-trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 7 trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: depth: 1 valid: 7 signed: 3 trust: 0-, 0q, 4n, 3m, 0f, 0u
gpg: the next trustdb check will be done on 2007-09-15



The first line shows you the actual trust policy used by your GnuPG installation, and which you can modify at your needs. It states that a key in your keyring is valid if it has been signed by at least 3 marginally trusted keys, or by at least one fully trusted key.

The second line describes the key of level 0, that is the key owned by you. It states that in your keyring you have one level zero key, which is signed by 7 keys. Furthermore among all the level zero keys, you have 0 of them for which you haven't yet evaluated the trust level. 0 of them are the keys for which you have no idea of which validity level to assign (q="I don't know or won't say"). You also have 0 keys that you do not trust at all (n="I do NOT trust"), 0 marginally trusted keys (m="I trust marginally"), 0 fully trusted keys (f="I trust fully") and 1 ultimately trusted keys (u="I trust ultimately").

The third line analyzes the keys of level 1 in your keyring. You have 7 fully valid keys, because you have personally signed them. Furthermore, among the keys that are stored in your keyring, you have 3 of them that are not signed directly by you, but are at least signed by one of the fully valid keys. The trust status counters have the same meaning of the ones in the second line. This time you have 4 keys signed by you but for which you do not trust at all the owner as signer of third party's keys. On the other side, 3 of the 7 keys that you have signed are marginally trusted. This means that you are only marginally confident that the owners of those keys can verify well the keys that they sign.
2010-06-03 11:25 | aa
# re: Linux/Windows下的文件加密 GnuPG  回复  更多评论   
null
2012-11-13 18:46 | 陆云峰
刷新评论列表
只有注册用户登录后才能发表评论。
 
Powered by:
IT博客
Copyright © David