GPG Overview

article/2025/10/31 19:54:10

Overview

PGP目前支持的算法

  • 非对称算法: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
  • 对称算法: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH, CAMELLIA128, CAMELLIA192, CAMELLIA256
  • 哈希算法: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
  • 压缩算法: Uncompressed, ZIP, ZLIB, BZIP2

除非量子计算机落地,目前来说2048位的RSA加密是不可破解的。

GPG

生成密钥

gpg --gen-key# orgpg --full-generate-key

output

gpg (GnuPG) 2.2.4; Copyright (C) 2017 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.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? (3072) 
Requested keysize is 3072 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) yGnuPG needs to construct a user ID to identify your key.Real name: Gavin Gao
Email address: cggos@outlook.com
Comment: 
You selected this USER-ID:"Gavin Gao <cggos@outlook.com>"Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
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: key 94FB606ACFB828F6 marked as ultimately trusted
gpg: directory '/home/cg/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/home/cg/.gnupg/openpgp-revocs.d/D06142ABCC08402AFCDB2FAF94FB606ACFB828F6.rev'
public and secret key created and signed.pub   rsa3072 2022-04-28 [SC]D06142ABCC08402AFCDB2FAF94FB606ACFB828F6
uid                      Gavin Gao <cggos@outlook.com>
sub   rsa3072 2022-04-28 [E]

其中,Key ID

94FB606ACFB828F6

私钥的密码为

xxxx gpg

生成子密钥

你日常使用应该使用子密钥,主密钥除了签发新的子密钥不要使用。

建议为不同环境,不同用途都单独生成子密钥,互不干扰。

gpg --edit-key cggos@outlook.com

output

gpg (GnuPG) 2.2.4; Copyright (C) 2017 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.Secret key is available.sec  rsa3072/94FB606ACFB828F6created: 2022-04-28  expires: never       usage: SC  trust: ultimate      validity: ultimate
ssb  rsa3072/BB0088AB554CF92Dcreated: 2022-04-28  expires: never       usage: E   
[ultimate] (1). Gavin Gao <cggos@outlook.com>gpg> addkey 
Please select what kind of key you want:(3) DSA (sign only)(4) RSA (sign only)(5) Elgamal (encrypt only)(6) RSA (encrypt only)
Your selection? 4
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 
Requested keysize is 3072 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
Really create? (y/N) y
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.sec  rsa3072/94FB606ACFB828F6created: 2022-04-28  expires: never       usage: SC  trust: ultimate      validity: ultimate
ssb  rsa3072/BB0088AB554CF92Dcreated: 2022-04-28  expires: never       usage: E   
ssb  rsa3072/3384DE02354CC62Ecreated: 2022-04-28  expires: never       usage: S   
[ultimate] (1). Gavin Gao <cggos@outlook.com>gpg> save

撤销证书

生成一张"撤销证书",以备以后密钥作废时,可以请求外部的公钥服务器撤销你的公钥

gpg --gen-revoke 94FB606ACFB828F6

output

sec  rsa3072/94FB606ACFB828F6 2022-04-28 Gavin Gao <cggos@outlook.com>Create a revocation certificate for this key? (y/N) y
Please select the reason for the revocation:0 = No reason specified1 = Key has been compromised2 = Key is superseded3 = Key is no longer usedQ = Cancel
(Probably you want to select 1 here)
Your decision? 
Enter an optional description; end it with an empty line:
> 
Reason for revocation: Key has been compromised
(No description given)
Is this okay? (y/N) y
ASCII armored output forced.
-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: This is a revocation certificateiQG2BCABCgAgFiEE0GFCq8wIQCr82y+vlPtgas+4KPYFAmJqewwCHQIACgkQlPtg
as+4KPYkDgv9FsNmqApXiu/p9y/M9pLQHgnQwmRbmjCEhZ+qpfQX2s5+zhpWQOtj
WqtL9EwM12Wld/aLsFnsjd1cU8hE5FpaPIt3slSNPIjqF5n1JKZqHkK850XKj2Z7
MMBsA6t3P7p7VSpP2oS0/d3q5bio9z37HePlp67gGYMHINsiVfHlrNBCNhhQ8K1q
yZmAORtbr0X2WS+ljG8aqqFg5dlG7WAhK/MugbKIFzdkc5Xugu5oQUgq3uogXGZg
o30/GS4a5KyTNSSWbO1vMA/tfYlhDsN+ywqqrStCGWCjO/JJk9Am6eG16zf9wyCW
PtXjc67X5WiOR+t2SWkbVcGZFJMlAdQwRF/D64qskGvap96qj8+I3U9hNaqG8W5A
5dO+vPEocDhPs0AqGzytFVmG88EyOIenhvVc8xtO9JrkFFUN0XBdsQoA162RH2tv
XH25wy3ZSzkdCXKYlQHFM7SIg6Lhfxl/j3ucueWlVciECEKnqixTw6Uq/Px/T+8h
Fv1vvK63BrJy
=BuV4
-----END PGP PUBLIC KEY BLOCK-----
Revocation certificate created.Please move it to a medium which you can hide away; if Mallory gets
access to this certificate he can use it to make your key unusable.
It is smart to print this certificate and store it away, just in case
your media become unreadable.  But have some caution:  The print system of
your machine might store the data and make it available to others!

列出本地密钥

gpg --list-keys
# or
gpg --list-secret-keys

output

/home/cg/.gnupg/pubring.kbx
---------------------------
pub   rsa3072 2022-04-28 [SC]D06142ABCC08402AFCDB2FAF94FB606ACFB828F6
uid           [ultimate] Gavin Gao <cggos@outlook.com>
sub   rsa3072 2022-04-28 [E]
gpg --list-secret-keys --fingerprint --keyid-format longgpg --fingerprint -K --keyid-format long
/home/cg/.gnupg/pubring.kbx
---------------------------
sec   rsa3072/94FB606ACFB828F6 2022-04-28 [SC]Key fingerprint = D061 42AB CC08 402A FCDB  2FAF 94FB 606A CFB8 28F6
uid                 [ultimate] Gavin Gao <cggos@outlook.com>
ssb   rsa3072/BB0088AB554CF92D 2022-04-28 [E]
ssb   rsa3072/3384DE02354CC62E 2022-04-28 [S]

导出密钥

public key

gpg -ao public-key.txt --export [用户ID]gpg --armor --output public-key.txt --export 94FB606ACFB828F6

Private Key

你日常使用应该使用子密钥,主密钥除了签发新的子密钥不要使用。

建议为不同环境,不同用途都单独生成子密钥,互不干扰。

gpg --armor --output private-key.txt --export-secret-keys 94FB606ACFB828F6# keybase
gpg --export-secret-keys -a 94FB606ACFB828F6# 注意这里最后 要带上“!”, 不然会导出全部子密钥
gpg -ao secret-key.txt  --export-secret-key     94FB606ACFB828F6! 		# 导出主私钥,建议secret-key 替换为你的加密设备备份文件的路径,直接导入到设备中
gpg -ao subkey-s.txt    --export-secret-subkeys 3384DE02354CC62E!   	# 导出有[S]标识、签名用子私钥
gpg -ao subkey-e.txt    --export-secret-subkeys BB0088AB554CF92D!     # 导出有[E]标识、加密用子私钥 ,这里的ID替换为你的子密钥ID# 别忘了同时将你刚刚生成的撤销凭证也备份起来

删除本地密钥

gpg --delete-secret-keys [用户ID]  # 删除私钥, UID 也可以替换成子密钥ID, 主密钥Key IDgpg --delete-keys [用户ID]		      # 删除公钥
gpg --delete-key [用户ID]# 如果想全部删除推荐直接删文件夹,即删除 $HOME/.gnupg
gpg (GnuPG) 2.2.4; Copyright (C) 2017 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.sec  rsa3072/94FB606ACFB828F6 2022-04-28 Gavin Gao <cggos@outlook.com>Delete this key from the keyring? (y/N) y
This is a secret key! - really delete? (y/N) ypub  rsa3072/94FB606ACFB828F6 2022-04-28 Gavin Gao <cggos@outlook.com>Delete this key from the keyring? (y/N) y

公钥服务器

keyserver

  • keys.openpgp.org
  • keyserver.ubuntu.com
  • pgp.mit.edu
  • subkeys.pgp.net
  • www.gpg-keyserver.de

配置 默认

# ~/.gnupg/gpg.confkeyserver hkps://keys.openpgp.orgkeyid-format 0xlong
with-fingerprint

上传

gpg --keyserver hkps://keys.openpgp.org --send-keys 94FB606ACFB828F6

验证邮箱

浏览器搜索查询

搜索

gpg --keyserver hkps://keys.openpgp.org --search-keys 94FB606ACFB828F6# orgpg --keyserver hkps://keys.openpgp.org --search-keys cggos@outlook.com

output

gpg: data source: https://keys.openpgp.org:443
(1)	Gavin Gao <cggos@outlook.com>3072 bit RSA key 94FB606ACFB828F6, created: 2022-04-28
Keys 1-1 of 1 for "94FB606ACFB828F6".  Enter number(s), N)ext, or Q)uit > N

公钥指纹

由于公钥服务器没有检查机制,任何人都可以用你的名义上传公钥,所以没有办法保证服务器上的公钥的可靠性。通常,你可以在网站上公布一个公钥指纹,让其他人核对下载到的公钥是否为真。fingerprint参数生成公钥指纹。

gpg --fingerprint 94FB606ACFB828F6gpg --fingerprint -K --keyid-format long

output

pub   rsa3072 2022-04-28 [SC]D061 42AB CC08 402A FCDB  2FAF 94FB 606A CFB8 28F6
uid           [ultimate] Gavin Gao <cggos@outlook.com>
sub   rsa3072 2022-04-28 [E]

导入密钥

从文件import

gpg --import [密钥文件] # 刚刚备份的子密钥文件, 或者其他人的公钥gpg --import subkey-s.txt
gpg: key 94FB606ACFB828F6: "Gavin Gao <cggos@outlook.com>" not changed
gpg: To migrate 'secring.gpg', with each smartcard, run: gpg --card-status
gpg: key 94FB606ACFB828F6: secret key imported
gpg: Total number processed: 1
gpg:              unchanged: 1
gpg:       secret keys read: 1
gpg:   secret keys imported: 1

从公钥服务器上获取公钥:

gpg --keyserver keys.openpgp.org --recv-keys 94FB606ACFB828F6

output

gpg: key 94FB606ACFB828F6: public key "Gavin Gao <cggos@outlook.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1

Keybase

keybase pgp select
You are selecting a PGP key from your local GnuPG keychain, and
will publish a statement signed with this key to make it part of
your Keybase.io identity.Note that GnuPG will prompt you to perform this signature.You can also import the secret key to *local*, *encrypted* Keybase
keyring, enabling decryption and signing with the Keybase client.
To do that, use "--import" flag.Learn more: keybase pgp help select#    Algo    Key Id             Created   UserId
=    ====    ======             =======   ======
1    3072R   94FB606ACFB828F6             Gavin Gao <cggos@outlook.com>
Choose a key: 1
▶ INFO Generated new PGP key:
▶ INFO   user: Gavin Gao <cggos@outlook.com>
▶ INFO   3072-bit RSA key, ID 94FB606ACFB828F6, created 2022-04-28

应用

文件验证

签名

gpg --detach-sign demo.txt

验证

gpg --verify demo.txt.sig demo.txt
gpg: Signature made Thu 28 Apr 2022 08:14:27 PM CST
gpg:                using RSA key C8BA9D0647339A178B7545F03384DE02354CC62E
gpg: Good signature from "Gavin Gao <cggos@outlook.com>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: D061 42AB CC08 402A FCDB  2FAF 94FB 606A CFB8 28F6Subkey fingerprint: C8BA 9D06 4733 9A17 8B75  45F0 3384 DE02 354C C62E

信任

gpg --edit-key cggos@outlook.comgpg (GnuPG) 2.2.4; Copyright (C) 2017 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.pub  rsa3072/94FB606ACFB828F6created: 2022-04-28  expires: never       usage: SC  trust: unknown       validity: unknown
sub  rsa3072/3384DE02354CC62Ecreated: 2022-04-28  expires: never       usage: S   
sub  rsa3072/BB0088AB554CF92Dcreated: 2022-04-28  expires: never       usage: E   
[ unknown] (1). Gavin Gao <cggos@outlook.com>gpg> trust 
pub  rsa3072/94FB606ACFB828F6created: 2022-04-28  expires: never       usage: SC  trust: unknown       validity: unknown
sub  rsa3072/3384DE02354CC62Ecreated: 2022-04-28  expires: never       usage: S   
sub  rsa3072/BB0088AB554CF92Dcreated: 2022-04-28  expires: never       usage: E   
[ unknown] (1). Gavin Gao <cggos@outlook.com>Please decide how far you trust this user to correctly verify other users' keys
(by looking at passports, checking fingerprints from different sources, etc.)1 = I don't know or won't say2 = I do NOT trust3 = I trust marginally4 = I trust fully5 = I trust ultimatelym = back to the main menuYour decision? 5
Do you really want to set this key to ultimate trust? (y/N) ypub  rsa3072/94FB606ACFB828F6created: 2022-04-28  expires: never       usage: SC  trust: ultimate      validity: unknown
sub  rsa3072/3384DE02354CC62Ecreated: 2022-04-28  expires: never       usage: S   
sub  rsa3072/BB0088AB554CF92Dcreated: 2022-04-28  expires: never       usage: E   
[ unknown] (1). Gavin Gao <cggos@outlook.com>
Please note that the shown key validity is not necessarily correct
unless you restart the program.gpg> 
gpg: signal Interrupt caught ... exiting

git

https://docs.github.com/cn/authentication/managing-commit-signature-verification

**能用来放在博客简介里作为身份的象征 增加联系你的安全方式

用来代替SSH

涌有了自己pgp key之后,就可以用 gpg-agent 来代替 OpenSSH Agent来进行 SSH操作了。不过替换了之后并不会增加SSH的安全性,额, 折腾精神不死嘛。

硬要说好处的话,大概就可以更方便地使用Yubikey(一种硬件加密智能卡)来SSH。

apt-get

apt-get update 或者aptitude update出现以下错误:

The following signatures couldn’t be verified because the public key is not available: : NO_PUBKEY B5B7720097BB3B58

解决方法:

# 从任何一个key server获得缺失的公钥B5B7720097BB3B58。
gpg --keyserver subkeys.pgp.net --recv-keys B5B7720097BB3B58# 导入公钥B5B7720097BB3B58。
gpg -a --export B5B7720097BB3B58 | sudo apt-key add -curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

http://chatgpt.dhexx.cn/article/dHMXHhCP.shtml

相关文章

GPG 使用初步

GPG 使用初步 1. PGP 软件的安装 PGP 的版本有很多&#xff0c;但由于其商业软件的特性&#xff0c;不能自由使用&#xff0c;自由软件基金会决定开发一个 PGP 的替代品&#xff0c;取名为 GnuPG &#xff0c;这就是 PGP 的由来   GPG 是基于命令行的程序&#xff0c;主要面…

gpg加解密软件学习

为什么要学习gpg呢&#xff1f;因为要在Linux下把一个邮箱的密码加密&#xff0c;不让其他人看到该邮箱真正的密码。 为了不让其他人看到真正的邮箱密码&#xff0c;我们需要对其进行加密。 加密的方式是先把密码先写到一个文件A中&#xff0c;然后使用相关的加密软件对该文件…

java动态代理

java动态代理实现与原理详细分析 原文地址 关于Java中的动态代理&#xff0c;我们首先需要了解的是一种常用的设计模式--代理模式&#xff0c;而对于代理&#xff0c;根据创建代理类的时间点&#xff0c;又可以分为静态代理和动态代理。 一、代理模式 代理模式是常用的java…

动态规划 --- 算法思想介绍

一.动态规划的基本概念 动态规划在五种算法设计方法中难度最大&#xff0c;它建立在最优原则的基础上.采用动态规划方法&#xff0c;可以高效地解决许多用贪婪算法或分治法无法解决的问题.动态规划(dynamic programming)属运筹学中的规划论分支&#xff0c;是求解决策过程最优…

动态规划算法详解

动态规划算法通常用于求解具有最优性质的问题 基本概念 动态规划过程是&#xff1a;每次决策依赖于当前状态&#xff0c;又随即引起状态的转移。一个决策序列就是在变化的状态中产生出来的&#xff0c;所以&#xff0c;这种多阶段最优化决策解决问题的过程就称为动态规划(DP)。…

动态规划原理

1. 基本概念 动态规划通过拆分问题&#xff0c;将问题拆分成许多的子问题&#xff0c;定义问题状态和状态之间的关系&#xff08;即状态转移方程或递推公式&#xff09;&#xff0c;使得问题能够以递推&#xff08;或者说分治&#xff09;的方式去解决。按顺序求解子问题&…

动态代理详解

想要更加透彻的理解动态代理&#xff0c;首先要熟悉下静态代理 一、静态代理 总结来说&#xff1a;目标类和代理类实现了相同的接口&#xff0c;在代理类中依赖了目标类&#xff0c;代理类的方法中调用了目标类的方法&#xff0c;并做了一些增强性的工作。 1、实现静态代理&…

CAD动态块制作

CAD动态块制作 拉伸动态块柜体A拉伸动态块制作第一步&#xff1a;制作柜体A第二步&#xff1a;进入块编辑器编辑第三步&#xff1a;关闭块编辑器 柜体B拉伸动态块制作第一步&#xff1a;制作柜体B第二步&#xff1a;进入块编辑器第三步&#xff1a;关闭块编辑器 可见性动态块第…

数据有效性 动态选择

EXCEL有两列数据栏&#xff0c;A列和B列&#xff0c;都是通过下来框来选择&#xff0c;要求A列选择完成后&#xff0c;B列动态调整可选择的内容。例如&#xff1a;第一例选择“AA”&#xff0c;第二列可供选择的范围是“a-d”&#xff1b;第一例选择“BB”&#xff0c;第二列可…

OTP 动态口令验证

OTP 动态口令验证。 简介 动态口令&#xff08;OTP&#xff0c;One-Time Password&#xff09;又称一次性密码&#xff0c;是使用密码技术实现的在客户端和服务器之间通过共享秘密的一种认证技术&#xff0c;是一种强认证技术&#xff0c;是增强目前静态口令认证的一种非常方…

loj#122.「强制在线」动态图连通性

loj#122. 「强制在线」动态图连通性 UPD:(7个月以后)这代码被叉了,我不想改了( negii真dl 然后发现这格式一更新…啊我的公式和链接怎么假掉了( csdn[] 算了不管了…反正这样子的话之后也不会用了( 题意 N 个点,M 次操作,支持加边/删边/询问两点间连通性。 强制在线。…

ORL、Yale等人脸数据库百度云链接

近段时间做人脸识别的实验&#xff0c;收集了几个人脸库&#xff0c;如图 这里放出百度云的链接&#xff0c;需要的自取 链接&#xff1a;https://pan.baidu.com/s/11_7bFdo_hhc83WQXmWtxvw 提取码&#xff1a;5ohd 强推这个文章&#xff0c;里面有16个人脸库的百度云链接 ht…

ORTP

1.为什么要使用RTP 一提到流媒体传输、一谈到什么视频监控、视频会议、语音电话&#xff08;VOIP&#xff09;&#xff0c;都离不开RTP协议的应用&#xff0c;但当大家都根据经验或者别人的应用而选择RTP协议的时候&#xff0c;你可曾想过&#xff0c;为什么我们要使用RTP来进行…

oracle中or的使用,Oracle Or

oracle函数 的 Oracle Or 在本教程中,我们来学习如何使用Oracle OR运算符来组合两个或更多的布尔表达式。 Oracle OR运算符介绍 OR运算符是一个逻辑运算符,它组合了布尔表达式,如果其中一个表达式为真(true),则返回true。 以下说明OR运算符的语法: expression_1 AND expre…

基于PCA方法的ORL人脸识别及Python代码实现

基于PCA方法的ORL人脸识别及Python代码实现 PCA算法方案设计代码实现结果分析参考文献 PCA的理论知识已经有很多博客做了清晰的解释&#xff0c;主要概括为找到投影的面使得类间误差最大&#xff0c;转化为找到构建的协方差的特征值与特征向量&#xff0c;在新的投影方向&#…

ORL Character Recgnition

文章目录 ORL Character Recgnition0 Abstract1 Introduction2 Related Work2.1 Character recognition2.2 Text detection 3 Connection Text Proposal Network3.1 Anchor3.2 Bi-Directional LSTM3.3 RPN layer3.4 Text line constructor3.5 Loss function3.6 Total system3.7…

ORL Faces Database介绍

ORL人脸数据集共包含40个不同人的400张图像&#xff0c;是在1992年4月至1994年4月期间由英国剑桥的Olivetti研究实验室创建。 此数据集下包含40个目录&#xff0c;每个目录下有10张图像&#xff0c;每个目录表示一个不同的人。所有的图像是以PGM格式存储&#xff0c;灰度图&…

基于ORL人脸数据库和PCA特征降维算法的人脸识别matlab仿真

目录 1.算法仿真效果 2.MATLAB核心程序 3.算法涉及理论知识概要 4.完整MATLAB 1.算法仿真效果 matlab2022a仿真结果如下&#xff1a; 2.MATLAB核心程序 ...................................................................... for i1:40sub_dir strcat(s, num2str(i))…

【图像处理matlab】PCA+KNN人脸识别 ORL人脸数据集

文章目录 0.写在前面1. 数据集导入与划分2. train-PCA构建脸空间2.1 原始数据导入2.2 去中心化2.3 求解协方差矩阵、特征值、特征向量2.4 特征脸选取--脸空间 3. test-物以类聚 KNN分类3.1 KNN简介3.2 KNN实现步骤3.2.1 距离度量---欧式距离、豪斯多夫距离.......3.2.2 k值选择…

Orcal 数据库

目录 一、数据库 1. 数据库概念 2. SQL 语言 3. Oracle结构 4. 表&#xff08;Table&#xff09; 5. 三范式 6. SELECT 语句 二、Orcal 基本操作 1. 查询列&#xff08;字段&#xff09; 2. 查询行&#xff08;记录&#xff09; 2.1 比较条件 2.2 且或非 2.3 null…