如何在 Linux 和 Windows 上更改 GnuPG 中的默认密码?

信息安全 视窗 linux gnupg
2021-09-03 12:59:01

如何将 GnuPG 使用的默认对称密码从 CAST5 更改为另一个?

我在 Windows 上使用 GPG4Win,但也对 Linux 的解决方案感兴趣。

2个回答

如果图形用户界面中没有选项,请改为编辑 GnuPG 的配置文件。最后,GnuPG 的图形用户界面除了调用 GnuPG 命令行之外什么都不做。

加密给其他人

有两个选项可以设置用于加密给其他人的算法:cipher-algo [algorithm]personal-cipher-preferences [algorithm]后者是首选,因为它既考虑了其他用户的算法能力和偏好,又符合 OpenPGP 标准;whilecipher-algo强制执行给定的算法。

您可以通过运行来查找可用的算法gpg --version,在 Windows 上您可能需要调用gpg.exe --versioncd到之前的安装目录。示例输出可能包括:

Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256

要强制使用AES256,请编辑您的gpg.conf文件并添加以下行:

personal-cipher-preferences AES256

接收加密消息

您还可以设置首选项,您希望其他人在向您发送加密消息时选择哪些算法。这可能仅在命令行上可用,但无论对方使用什么客户端应用程序都会产生影响(但请记住:这只是您的偏好的建议,而不是强制执行,与cipher-algo上面的比较)。

gpg --edit-key [key-id]使用(替换[key-id]为您的密钥 ID,您可能必须gpg.exe再次使用,如上所述)启动编辑菜单。在里面,您可以使用showpref列出当前设置的首选项,并setpref更改它们。这样做的用户界面很糟糕,你必须提供一长串密码、摘要和压缩算法,而首选的总是必须首先列出。

debian-administration.org 上的一篇文章描述了这个过程,并提出了以下偏好,这似乎是合理的:

setpref SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed

更新:对于 Gpg4win,我看到两个选项:

  • 对于 S/MIME,GUI 有一个设置它的地方(设置 -> 配置 Kleopatra -> GnuPG 系统 -> GPG for S/MIME -> 使用密码算法)
  • 否则,您必须更改底层 gpg.conf 文件

@jens-erat 已经更深入地描述了后者,但我将根据自己的使用情况提供以下输入:

  1. 您要使用的命令行 gpg 是 %INSTALLDIR%\gpg2.exe;在我的系统上运行到 C:\Program Files (x86)\GNU\GnuPG
  2. 您可以通过运行gpg2 --version并查找以下行来找到您的 homedir(您需要放置 gpg.conf)Home: C:/Users/gowenfawr/AppData/Roaming/gnupg

原始(非 GUI)答案:

如果您使用的是命令行 gpg,那么--cipher-algo参数将允许您选择您的密码,并且您可以使用--version查看哪些密码可用。

(此处在 Linux 上显示的测试,应该等效于 Windows)

$ gpg --version
gpg (GnuPG) 1.4.16
Copyright (C) 2013 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: ~/.gnupg
Supported algorithms:
Pubkey: RSA, RSA-E, RSA-S, ELG-E, DSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2
$ file test*
test1.txt: ASCII text
test2.txt: ASCII text
$ gpg --cipher-algo TWOFISH -c test1.txt 
Enter passphrase: 
Repeat passphrase: 
$ gpg --cipher-algo AES256 -c test2.txt 
Enter passphrase: 
Repeat passphrase: 
$ file test*
test1.txt:     ASCII text
test1.txt.gpg: GPG symmetrically encrypted data (TWOFISH cipher)
test2.txt:     ASCII text
test2.txt.gpg: GPG symmetrically encrypted data (AES256 cipher)
$