当前位置: 首页 > news >正文

Windows cmd下的GNUgpg的使用方法

生成自己的密钥对:

使用GnuPG之前必须生成密钥对(公钥和私钥),参数选项”–gen-key”可以生成密钥对。可按如下步骤操作。

cygwin@imdba.cn /cygdrive/c/gnupg
$ gpg.exe –gen-key
gpg (GnuPG) 1.4.9; Copyright (C) 2008 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

gpg: WARNING: using insecure memory!
gpg: please see http://www.gnupg.org/faq.html for more information
gpg: directory `/home/Administrator/.gnupg’ created
gpg: new configuration file `/home/Administrator/.gnupg/gpg.conf’ created
gpg: WARNING: options in `/home/Administrator/.gnupg/gpg.conf’ are not yet active during this run
gpg: keyring `/home/Administrator/.gnupg/secring.gpg’ created
gpg: keyring `/home/Administrator/.gnupg/pubring.gpg’ created
Please select what kind of key you want:
(1) DSA and Elgamal (default)
(2) DSA (sign only)
(5) RSA (sign only)
Your selection? [回车]
DSA keypair will have 1024 bits.
ELG-E keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 2048
Requested keysize is 2048 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>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 the Real Name, Comment and Email Address in this form:
“Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>”

Real name: Nova
Name must be at least 5 characters long
Real name: xinxing
Email address: imdba@imdba.cn
Comment: imdba.cn
You selected this USER-ID:
“xinxing (imdba.cn) <imdba@imdba.cn>”

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 good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
.++++++++++.++++++++++++++++++++.++++++++++++++++++++++++++++++.+++++.++++++++++ ++++++++++.++++++++++.+++++.++++++++++++++++++++++++++++++>++++++++++……….. ..>+++++..<+++++……………………+++++
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
+++++++++++++++..++++++++++++++++++++++++++++++.++++++++++++++++++++.+++++++++++ +++++++++.++++++++++++++++++++.+++++++++++++++++++++++++++++++++++…+++++>…++ ++++++++>+++++………..>+++++…………………………………………. …>+++++<.+++++………+++++^^^^^^^^^
gpg: /home/Administrator/.gnupg/trustdb.gpg: trustdb created
gpg: key C2839106 marked as ultimately trusted
public and secret key created and signed.
gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
pub 1024D/C2839106 2009-10-24
Key fingerprint = 3851 295C D23C 2FC1 FFC7 9B9B E65C 6392 C283 9106
uid xinxing (imdba.cn) <imdba@imdba.cn>
sub 2048g/8F1EB3E9 2009-10-24

导出公钥,提供给他人加密文件传输用

cygwin@imdba.cn /cygdrive/c/gnupg
$ gpg –output pubring.gpg –export –armor> xinxing.asc

cygwin@imdba.cn /cygdrive/c/gnupg
$ gpg –output imdba.cn.asc –export –armor> xinxing.asc
cygwin@imdba.cn /cygdrive/c/gnupg

导入别人提供给自己的公钥

cygwin@imdba.cn /cygdrive/c/gnupg
$ gpg –import xinxingcyou.asc

列出自己拥有的用户的公钥列表

$ gpg.exe –list-keys
gpg: WARNING: using insecure memory!
gpg: please see http://www.gnupg.org/faq.html for more information
/home/Administrator/.gnupg/pubring.gpg
————————————–
pub 1024D/C2839106 2009-10-24
uid xinxing (imdba.cn) <imdba@imdba.cn>
sub 2048g/8F1EB3E9 2009-10-24

pub 1024D/294862C4 2009-06-24
uid xinxing <xinxing@cyou.com>
sub 2048g/A895F53A 2009-06-24

cygwin@imdba.cn /cygdrive/c/gnupg
$ gpg –fingerprint 294862C4
gpg: WARNING: using insecure memory!
gpg: please see http://www.gnupg.org/faq.html for more information
pub 1024D/294862C4 2009-06-24
Key fingerprint = C006 D074 3152 A938 42AD 4DE3 489A 8741 2948 62C4
uid xinxing <xinxing@cyou.com>
sub 2048g/A895F53A 2009-06-24

导入密钥之后,可以使用 –sign-key 选项进行签名,签名的目的是证明您完全信任这个xinxing_cyou.asc证书的合法性。

cygwin@imdba.cn /cygdrive/c/gnupg
$ gpg –sign-key 294862C4
gpg: WARNING: using insecure memory!
gpg: please see http://www.gnupg.org/faq.html for more information

pub 1024D/294862C4 created: 2009-06-24 expires: never usage: SC
trust: unknown validity: unknown
sub 2048g/A895F53A created: 2009-06-24 expires: never usage: E
[ unknown] (1). xinxing <xinxing@cyou.com>

pub 1024D/294862C4 created: 2009-06-24 expires: never usage: SC
trust: unknown validity: unknown
Primary key fingerprint: C006 D074 3152 A938 42AD 4DE3 489A 8741 2948 62C4

xinxing <xinxing@cyou.com>

Are you sure that you want to sign this key with your
key “xinxing (imdba.cn) <imdba@imdba.cn>” (C2839106)

Really sign? (y/N) y

You need a passphrase to unlock the secret key for
user: “xinxing (imdba.cn) <imdba@imdba.cn>”
1024-bit DSA key, ID C2839106, created 2009-10-24

对文件加密过程:首先列出对可用加密的用户列表
cygwin@imdba.cn /cygdrive/c/gnupg
$ gpg.exe –list-keys
gpg: WARNING: using insecure memory!
gpg: please see http://www.gnupg.org/faq.html for more information
/home/Administrator/.gnupg/pubring.gpg
————————————–
pub 1024D/C2839106 2009-10-24
uid xinxing (imdba.cn) <imdba@imdba.cn>
sub 2048g/8F1EB3E9 2009-10-24

pub 1024D/294862C4 2009-06-24
uid xinxing <xinxing@cyou.com>
sub 2048g/A895F53A 2009-06-24

对文件check_mysqlpr.sh进行加密

cygwin@imdba.cn /cygdrive/c/gnupg
$ gpg –sign –encrypt check_mysqlpr.sh
gpg: WARNING: using insecure memory!
gpg: please see http://www.gnupg.org/faq.html for more information

You need a passphrase to unlock the secret key for
user: “xinxing (imdba.cn) <imdba@imdba.cn>”
1024-bit DSA key, ID C2839106, created 2009-10-24
You did not specify a user ID. (you may use “-r”)
Current recipients:
Enter the user ID. End with an empty line: C2839106
Current recipients:
2048g/8F1EB3E9 2009-10-24 “xinxing (imdba.cn) <imdba@imdba.cn>”
Enter the user ID. End with an empty line: 294862C4
Current recipients:
2048g/A895F53A 2009-06-24 “xinxing <xinxing@cyou.com>”
2048g/8F1EB3E9 2009-10-24 “xinxing (imdba.cn) <imdba@imdba.cn>”
Enter the user ID. End with an empty line: 输入空格才会结束

对文件进行解密过程:

cygwin@imdba.cn /cygdrive/c/gnupg
$ gpg -d check_mysqlpr.sh.gpg >check_mysqlpr.sh
gpg: WARNING: using insecure memory!
gpg: please see http://www.gnupg.org/faq.html for more information

You need a passphrase to unlock the secret key for 输入密码
user: “xinxing (imdba.cn) <imdba@imdba.cn>”
2048-bit ELG-E key, ID 8F1EB3E9, created 2009-10-24 (main key ID C2839106)

gpg: encrypted with 2048-bit ELG-E key, ID A895F53A, created 2009-06-24
“xinxing <xinxing@cyou.com>”
gpg: encrypted with 2048-bit ELG-E key, ID 8F1EB3E9, created 2009-10-24
“xinxing (imdba.cn) <imdba@imdba.cn>”
gpg: Signature made Sat Oct 24 12:26:20 2009 using DSA key ID C2839106
gpg: Good signature from “xinxing (imdba.cn) <imdba@imdba.cn>”
cygwin@imdba.cn /cygdrive/c/gnupg
$

参考文章: http://www.gnupg.org/faq.html
http://www.imdba.cn/2009/10/24/windows-cmd-gnugpg-manul/

相关文章:

  • Codeforces Round #653 (Div. 3)(A-E1)
  • Linux hdparm命令使用方法
  • UVA - 11582 Colossal Fibonacci Numbers!(找循环节)
  • UVA - 12169 Disgruntled Judge(枚举+扩展欧几里得)
  • ASM管理命令和操作笔记
  • UVA - 10791 Minimum Sum LCM(质因数分解)
  • 删除ASM残留信息方法和重建步骤
  • UVA - 12716 GCD XOR(找规律+枚举技巧)
  • Oracle 修改归档模式
  • UVA - 1635 Irrelevant Elements(质因数分解)
  • spfile和pifle的一点浅浅的认识
  • 欧拉函数
  • UVA - 1636 Headshot(条件概率)
  • Oracle RAC日常基本维护命令
  • UVA - 11181 Probability|Given(条件概率+状压dfs)
  • 网络传输文件的问题
  • [译]如何构建服务器端web组件,为何要构建?
  • Angularjs之国际化
  • angular学习第一篇-----环境搭建
  • ES6--对象的扩展
  • Essential Studio for ASP.NET Web Forms 2017 v2,新增自定义树形网格工具栏
  • Hexo+码云+git快速搭建免费的静态Blog
  • node学习系列之简单文件上传
  • Spark RDD学习: aggregate函数
  • 分类模型——Logistics Regression
  • 关于for循环的简单归纳
  • 基于Javascript, Springboot的管理系统报表查询页面代码设计
  • 漫谈开发设计中的一些“原则”及“设计哲学”
  • Linux权限管理(week1_day5)--技术流ken
  • ​插件化DPI在商用WIFI中的价值
  • ​软考-高级-系统架构设计师教程(清华第2版)【第1章-绪论-思维导图】​
  • #图像处理
  • (C++)八皇后问题
  • (笔试题)分解质因式
  • (分布式缓存)Redis哨兵
  • (十)T检验-第一部分
  • (十六)一篇文章学会Java的常用API
  • (五)Python 垃圾回收机制
  • (五)网络优化与超参数选择--九五小庞
  • (转)socket Aio demo
  • *上位机的定义
  • . ./ bash dash source 这五种执行shell脚本方式 区别
  • .net websocket 获取http登录的用户_如何解密浏览器的登录密码?获取浏览器内用户信息?...
  • .NET 使用 ILRepack 合并多个程序集(替代 ILMerge),避免引入额外的依赖
  • .NET/C# 推荐一个我设计的缓存类型(适合缓存反射等耗性能的操作,附用法)
  • .NET平台开源项目速览(15)文档数据库RavenDB-介绍与初体验
  • [ CTF ] WriteUp-2022年春秋杯网络安全联赛-冬季赛
  • [ai笔记4] 将AI工具场景化,应用于生活和工作
  • [Effective C++读书笔记]0012_复制对象时勿忘其每一部分
  • [Firefly-Linux] RK3568 pca9555芯片驱动详解
  • [go 反射] 进阶
  • [IDF]啥?
  • [JavaEE系列] Thread类的基本用法
  • [JavaScript]_[初级]_[关于forof或者for...of循环语句的用法]
  • [JS]变量