windows 使用 Gpg4win 命令行使用公钥进行批量加密

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36305319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:31:42  来源:igfitidea点击:

Batch encrypt with public key using Gpg4win command line

windowsbatch-fileencryptiongnupgopenpgp

提问by Eds

We are setting up our first EDI system that relies on incoming and outgoing file encryption using OpenPGP. The incoming files that are encrypted with our public key, we can successfully decrypt using our private key using Gpg4win's command line option:

我们正在建立我们的第一个 EDI 系统,该系统依赖于使用 OpenPGP 的传入和传出文件加密。使用我们的公钥加密的传入文件,我们可以使用我们的私钥使用 Gpg4win 的命令行选项成功解密:

gpg --batch --passphrase "SOME_KEY" --decrypt-files "%decryptingdir%\*.pgp"

What I now need to do, is the reverse, and encrypt the outgoing files using our partners public key.

我现在需要做的是反过来,使用我们的合作伙伴公钥加密传出的文件。

I have been unable to find any command line documentation around batch encryption using a public key. I assumed it would be something in the order of:

我一直无法找到有关使用公钥进行批量加密的任何命令行文档。我认为它会按以下顺序进行:

gpg --batch --encrypt-files "%encryptingfir%\*.pgp" --key "SOME_KEY_PATH"

Can anyone advise how I can achieve this encryption via the command line?

谁能建议我如何通过命令行实现这种加密?

回答by Jens Erat

Use the --recipientoption to denote keys to encrypt for. GnuPG has a distinction between options and commands, while options should better go first.

使用该--recipient选项来表示要加密的密钥。GnuPG 有选项和命令的区别,而选项最好放在第一位。

gpg --batch --recipient [key-id] --encrypt-files "%encryptingfir%\*.pgp"

GnuPG expects keys to be imported to the keychain, so gpg --import [key-file]it first. There are hacks using --keyring [your-key-file], but simply importing the key file is the safer way to go.

GnuPG 期望将密钥导入到钥匙串中,因此gpg --import [key-file]首先导入。有使用 hacks 的方法--keyring [your-key-file],但简单地导入密钥文件是更安全的方法。

For scripted/programmed operations, best practice is to always denote the full fingerprint. Read about key ID collisionsto understand the issues with short key IDs.

对于脚本/编程操作,最佳做法是始终表示完整的指纹。阅读密钥 ID 冲突以了解短密钥 ID 的问题。