Manage public private key

How to generate a key pair? / 怎样生成公私钥对?

gpg --gen-key

请选择您要使用的密钥种类:

(1) RSA and RSA (default)

(2) DSA and Elgamal

(3) DSA (仅用于签名)

(4) RSA (仅用于签名)

您的选择?

DSA and RSA are algorithm.

DSA和RSA是算法名子。算法

Choice 1 means creating two key pairs, both use RSA algorithm, one for signing, one for encrypting.

选项1表示制做两对公私钥,都使用RSA算法,一个公私钥用于签名,一个公私钥用于加密。

Choice 2 means creating two key pairs, one uses DSA algorithm, for signing, one uses Elgamal algorithm, for encrypting.

选项2表示制做两对公私钥,一个公私钥用DSA算法,用于签名,一个公私钥用Elgamal算法,用于加密。

Choice 3 means creating one key pair, use DSA algorithm, for both signing and encrypting.

选项3表示制做一对公私钥,使用DSA算法,用于签名和加密。

Choice 4 means creating one key pair, use RSA algorithm, for both signing and encrypting.

选项4表示制做一对公私钥,使用RSA算法,用于签名和加密。

Just follow the hints, do choices, at last it will output:

根据提示填,最后会获得输出:数据库

gpg: 正在检查信任度数据库

gpg: 须要 3 份勉强信任和 1 份彻底信任,PGP 信任模型

gpg: 深度:0 有效性: 4 已签名: 0 信任度:0-,0q,0n,0m,0f,4u

pub 2048D/84A0D639 2018-03-01

密钥指纹 = A46D 469C 051B 9EA0 F5FE C4CA 799D A3DC 84A0 D639

uid [ 绝对 ] abc (Address)

sub 2048g/50A8A3AA 2018-03-01

Fourth line, that '84A0D639', and seventh line, that '50A8A3AA', are IDs of the key pairs.

第四行那个84A0D639,第七行那个50A8A3AA,是生成的公私钥对的ID。promise

How to list your key pairs? / 怎样列出你拥有的公私钥对

List public keys:dom

gpg --list-public-keys

List private keys:ide

gpg --list-secret-keys

What is key pair? Where is your key pair? 什么是公私钥对,你生成的公私钥对在哪?

A 'key pair' consists of a public key and a private key.

公私钥对包含公钥和私钥。

but in GPG, a 'key pair' consists of a primary key pair and a subordinate key pair.

可是在GPG里,公私钥对包含一个主钥对和一个副钥对。ui

In cryptography, who is public, who is private is not important, these two roles are equal, and can be exchanged. If we say one key is a public key, then it is public key, and the other key is a private key.

密码学中,谁是公,谁是私不是必定的,这两个角色是平等的,可交换的。咱们能够说其中一个是公钥,谁就是公钥,另外一个钥就是私钥。

But in GPG, 'public key' what we said consists of:this

the public portion of the master signing key,

主钥对的公钥部分。

the public portions of the subordinate signing and encryption subkeys,

副钥对的公钥部分。

a set of user IDs used to associate the public key with a real person,

和公钥关联的,用于指示真人的用户id。

By default, GPG put its data under ~/.gnupg, this directory may has these files:

GPG把文件放在~/.gnupg下面,这个目录可能有这些文件:加密

.

├── openpgp-revocs.d

│ └── D4CE087C2A16C3EF81BEB9A0A1691041C934895B.rev

├── private-keys-v1.d

│ ├── 0DBEE5E9C5C25E304FC88AA8FFF38EEEB7826311.key

│ └── 8A5B9A60C63E11881D9C778477163BC4FD271B2B.key

├── pubring.kbx

├── pubring.kbx~

├── random_seed

└── trustdb.gpg

That 'pubring.kbx' is where your key pairs are.code

How to generate a revocation certificate / 怎样生成撤回证书(用于对外宣布做废一个公私钥对)

If you forget your passphrase or if your private key is compromised or lost, a revocation certificate may be published to notify others that the public key should no longer be used.

若是你忘了私钥的密码或私钥泄漏了,能够公布 撤回证书 以通知你们不要再使用那个公钥。

So after your keypair is created you should immediately generate a revocation certificate for the primary public key.

因此公私钥对做成后,你应该当即主公钥生成撤回证书。orm

gpg --gen-revoke --output revoke.asc BB2B8D466C53DBC559EABBA1D083B71756A6D115

--gen-revoke

means generating a 'revocation certificate'.

--output revoke.asc

means the output file is 'revoke.asc'.

BB2B80... is the id of the public key.

How to exchange public keys? / 怎样交换公钥?

If you want to exchange your public key to someone, first you need to 'export' it:

若是你想把你的公钥给另外一我的,你要先「导出」它:

gpg --export --output my-public-key.gpg D4CE087C2A16C3EF81BEB9A0A1691041C934895B

--export

means exporting public key.

表示导出公钥。

--output ...

the output filename.

表示输出文件。

you can use 'file' command to check that file's type:

你能够用file命令检查这个文件的类型:

file my-public-key.gpg

my-public-key.gpg: GPG key public ring, created Tue Feb 23 09:50:34 2021

you can also add an argument '--armor' to 'gpg --export' so you will get a plain text output file:

gpg --export --armor --output my-public-key.gpg D4CE087C2A16C3EF81BEB9A0A1691041C934895B

then send 'my-public-key.gpg' to the receiver.

而后把这个文件发给接收者。

then the receiver can 'import' this file:

接收者导入这个文件:

gpg --import my-public-key.gpg

then the receiver check whether he has import your key:

接收者检查他是否已导入了你的公钥:

gpg --list-public-keys

that is not the last step, the receiver need to 'trust' your public key:

这还没完,接收者要「确认」你的公钥:

gpg --edit-key D4CE087C2A16C3EF81BEB9A0A1691041C934895B

the above command will bring the receiver to an interactive program.

上述命令会带接收者进入一个交互程序。

then the receiver execute 'fpr' to check its fingerprint, it should have the same result that the sender checked.

接收者执行fpr命令检查指纹,应该获得与发送者所作的检查一致的结果。

gpg> fpr

pub rsa2048/A1691041C934895B 2021-02-23 iamyou

Primary key fingerprint: D4CE 087C 2A16 C3EF 81BE B9A0 A169 1041 C934 895B

then the receiver execute 'trust' to trust your public key:

接收者执行trust命令以信任你的公钥:

gpg> trust

you can use 'help' to see all the subcommands:

你能够用help命令查看全部子命令:

gpg> help

How to exchange private keys? / 怎样交换私钥?

gpg --export-secret-key --output my-private-key.gpg D4CE087C2A16C3EF81BEB9A0A1691041C934895B

--export-secret-key

means exporting a private key.

表示导出私钥。

--output

the output filename.

输出文件名。

you will be asked for your private key's password.

On the receiver side, he 'import' your private key:

gpg --import my-private-key

then he check private key ring:

gpg --list-secret-keys

How to delete a key? / 怎样删除公私钥?

How to delete a public key?

怎样删除公钥?

gpg --delete-key D4CE087C2A16C3EF81BEB9A0A1691041C934895B

How to delete a private key?

怎样删除私钥?

gpg --delete-secret-key D4CE087C2A16C3EF81BEB9A0A1691041C934895B

How to change private key password? / 怎样改私钥密码?

First execute 'gpg --edit-key':

gpg --edit-key D4CE087C2A16C3EF81BEB9A0A1691041C934895B

then execute subcommand 'passwd':

gpg> passwd

How to use GPG to encrypt a file? / 怎样用gpg加密文件?

Use public key to encrypt a file / 用公钥加密文件

If you have a plain text file 'plain.txt', you can use a receiver's public key to encrypt it, of course, you must have import that receiver's public key first.

若是你有一个文本文件plain.txt,你能够用一个接收者的公钥加密这个文件,固然,你得先导入那位接收者的公钥。

On that receiver's side, he exports he's public key:

接收者那边,他导出他的公钥:

gpg --export --public ReceiverPublicKey.gpg D4CE087C2A16C3EF81BEB9A0A1691041C934895B

he send 'ReceiverPublicKey.gpg' to you.

他把文件ReceiverPublicKey.gpg发给你。

you import this file:

你导入这个文件:

gpg --import ReceiverPublicKey.gpg

then you choose to trust his public key:

你选择信任他的公钥:

gpg --edit-key D4CE087C2A16C3EF81BEB9A0A1691041C934895B

gpg> trust

gpg> quit

then you use his public key to encrypt your file:

你用他的公钥加密你的文件:

gpg --encrypt --recipient D4CE087C2A16C3EF81BEB9A0A1691041C934895B --output EncryptedByPublicKey.gpg PlainText.txt

--encrypt

means encrypting a file using a public key.

表示用公钥加密文件

--recipient ...

who is the receiver. who is the receiver, then we use who's public key.

谁是接收者。谁是接收者,咱们就用谁的公钥。

--output ...

the output filename.

输出文件。

The last argument 'PlainText.txt' is the input file.

最后一个参数是输入文件。

You send 'EncryptedByPublicKey.gpg' to the receiver.

你把加密后的文件发给接收者。

On the receiver side, he use his private key to decrypt that file:

接收者那边,他用他的私钥解密文件:

gpg --decrypt --output PlainText.txt EncryptedByPublicKey.gpg

--decrypt

means decrypt a file.

表示解密文件。

--output ...

the output file.

输出文件。

The last argument is the encrypted file to be decrypted.

最后一个文件是要解密的被加密的文件。

The receiver do not need to specify his private key in the command, if you has the private key, GPG will automatically find and use it.

接收者不须要在命令里指定私钥,若是他有对应的私钥,gpg会自动找到并使用那个私钥。

But you can also specify what private key to use:

但你也能够指定私钥:

gpg --decrypt --local-user D4CE087C2A16C3EF81BEB9A0A1691041C934895B --output PlainText.txt EncryptedByPublicKey.gpg

--local-user ...

use which private key.

Use symmetric password to encrypt a file / 用对称密码加密文件

encrypt a file:

gpg --symmetric --output EncryptedByPassword.gpg PlainText.txt

--symmetric

means using symmetric password to encrypt a file.

表示用对称密码加密文件。

--output ...

the output file.

输出文件。

the last argument is the file to be encrypted.

最后一个参数是钥加密的文件。

decrypt the above encrypted file:

解密上面的被加密的文件:

gpg --decrypt --output PlainText.txt EncryptedByPassword.gpg

How to use GPG to sign a file? / 怎样用gpg对文件签名?

We use private key for signing, use public key for verifying.

咱们用私钥签名,用公钥确认。

Integrated signature / 签名与原文件合在一块儿

To sign a file:

对一个文件签名:

gpg --sign --output SignedFile --local-user D4CE087C2A16C3EF81BEB9A0A1691041C934895B PlainText.txt

--sign

means signing a file.

表示一个文件签名。

--output ...

the output filename.

输出文件。

--local-user ...

use which private key.

用哪一个私钥。

the last argument is the file to be signed.

最后一个参数是要被签名的文件。

then another man who has your public key, can verify 'SignedFile' and extract the original file:

拥有你的公钥的人能够「确认」这个签名文件,并解压出原文件:

gpg --decrypt --recipient D4CE087C2A16C3EF81BEB9A0A1691041C934895B --output PlainText.txt SignedFile

--decrypt

means decrypting a file, in this situation, we call this operation 'verify'.

--recipient ...

use which public key.

用哪一个公钥。

--output ...

the output file.

输出文件。

the last argument is the signed file to be verified.

最后一个参数是要被确认的被签名的文件。

he can also just 'verify' the signature:

他也能够只确认签名,不解压出原文件

gpg --verify --recipient D4CE087C2A16C3EF81BEB9A0A1691041C934895B SignedFile

Detached signature / 单独的签名文件

To create a detached signature.

生成一个独立的签名文件

gpg --detach-sign --output DetachedSignature --local-user D4CE087C2A16C3EF81BEB9A0A1691041C934895B PlainText.txt

--detach-sign

means making a detached signature, the output file contains only signing information.

表示产生一个独立的签名文件,输出文件只包含签名信息。

--output ...

the output file

输出文件。

--local-user ...

use which private key.

用哪一个私钥。

the last argument is the file to be signed.

最后一个参数是要被签名的文件。

then another man who has your public key , can verify 'DetachedSignature' and original 'PlainText.txt':

拥有你的公钥的人能够「确认」这个签名文件:

gpg --verify DetachedSignFile PlainText.txt

--verify ... ...

verify the signature and the original file, it follows two arguments, the first is a detached signature, the second is the original file.

确认签名文件和原文件,第一个参数是签名文件,第二个参数是原文件。

'gpg --verify' can follow one or more argument, if there is only one argument, it is a 'integrated signature', if there are two arguments, the first is a detached signature, the second is the original file.

'gpg --verify' 能够跟一或二个参数,若是只有一个参数,则这个参数是一个「集成式签名」,若是有两个参数,则第一个参数是独立签名文件,第二个参数是原文件。

gpg加密 java小程序,使用GPG相关推荐

  1. java 获取文件所在的文件夹_带你0基础编写一个Java小程序,领略Java程序从编写到编译再到运行的全流程...

    在学习Java之前我们需要先认识下什么是计算机语言?计算机语言又有哪些分类?在了解这些后对我们理解学习帮助是很大的. 要知道计算机语言是人与计算机之间进行信息交流沟通的一种特殊语言,又分为机械语言.汇 ...

  2. java小程序之学生信息_java小程序之学生信息录入界面

    小程序我的项目下载链接:点击打开链接 因为这学期比赛太多,蓝桥杯,团体程序设计大赛,ACM省赛等原因基本这学期的课程都没上,比赛完后开始去上课,java老师让用java写一个学生信息录入界面,把界面中 ...

  3. 【开发日常】【Java】Java小程序汽车租赁

    <Java小程序--汽车租赁> 1.描述:刚学Java写的小程序,用到类的继承,多态,abstract抽象方法. 2.工具:eclipse.exe 3.功能:选择子类(轿车 / 客车) 选 ...

  4. Wifi热点java_用笔记本电脑开启热点Java小程序

    用笔记本电脑开启热点Java小程序是一条命令设置笔记本成无线热点, 制作"开启无线热点工具,这个小工具实际上是用java来执行cmd命令来完成操作,当然也可以反射jar里边的字节码文件. 使 ...

  5. 简单Java小程序----有界面ATM机

    继<简单Java小程序---无界面ATM机>以后,尝试对有界面ATM机改写,对面向对象的了解又深了一层! 桌面的创建过程       由于使用的NetBean软件没有提供专用的控件拖拽使用 ...

  6. java小程序_Java小程序

    java小程序 An applet is a special kind of Java program that runs in a Java enabled browser. This is the ...

  7. 3.每天一个java小程序之累加累乘

    3.每天一个java小程序之累加累乘 java小练习之数的累加累乘,在于锻炼数学计算思维. 每天一个小程序,每天进步一点点. 代码如下: package com.zou; import java.ut ...

  8. 基于Bluemix快速构建部署一款Java小程序——微博影响力分析器

    一.前言 近年来IT界风云际会,各种新概念如大数据.云平台.虚拟化等,如雨后春笋般层出不穷.而云平台,可以说是近些年来引领时代新潮的边缘概念之一,各大厂商竞相推出各种云产品,抢占云市场高地.近期,IT ...

  9. dw网页插入java小程序_DW网页设计100例35:构建Java插入模块

    Java 是一种程序设计语言, Java applet ( Java 小程序)是在 Java 的基础上演变而成的.能够嵌入在网页中的.可以执行一定小任务的应用程序. 20060407140110aa1 ...

最新文章

  1. Redis requires a monkey patched socket library to work with gevent
  2. Python3实现邮箱发送
  3. 设计模式-模版方法模式
  4. 卷积核_漫画:卷积神经网络中的卷积核到底是什么?
  5. distenct oracle_oracle中distinct的用法详解
  6. 企业网站+Axure企业官网通用模板+公司官网通用模板+web端高保真原型+门户官网+物流企业+门户网站+服务中心+产品中心+新闻中心+帮助中心+企业官网+公司官网+公司网站+登录注册+高保真交互
  7. Git pull 强制覆盖本地文件
  8. 报错:mysqldump‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
  9. HDU 4403 A very hard Aoshu problem (DFS暴力)
  10. 【备用】SQL SERVER存储过程执行速度慢的问题
  11. python无限弹窗1.0
  12. 中职生c语言搜题软件,适合法考学生用的搜题软件,这几款帮你搞定!
  13. 摄影小白入门相机选择(个人出发)
  14. Eclipse配置优化
  15. 为什么五笔输入法打字那么快,现在使用的人却越来越少了?
  16. Dependency ‘org.mybatismybatisx.x.x‘ not found问题解决方法
  17. remote: Repository not found. fatal: repository ‘xxxxxxx‘ not found
  18. Iec61850 部署调试笔记一
  19. 网络1711班 C语言第一次作业批改总结
  20. ubuntu资源下载利器:多线程、断点续传下载工具mwget的安装与使用

热门文章

  1. 人生的智慧 读书笔记
  2. 计算机网络实验——交换机及VLAN的配置
  3. CleanShot X:屏幕截图、录屏、滚动截图、标注一个都不少
  4. 强化学习之Actor-Critic
  5. 笔记-项目采购管理-竞争性谈判采购和单一来源采购
  6. Ubuntu18.04 NX下用ZED2 双目立体相机进行SLAM
  7. 清华大学计算机与软件工程学院,清华大学林闯教授应邀至计算机科学与软件工程学院授课...
  8. c语言中继承的好处,c语言中,继承和和组合有什么区别
  9. 直播合辑 | 微软ATP与您相约100场公益演讲
  10. 主板芯片介绍---被AMD收购的Ati芯片组(五)