gpt4 book ai didi

linux - 具有三重管道和 key 文件的 GPG

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:52:29 25 4
gpt4 key购买 nike

我想 tar,用 xz 压缩,然后使用 key 文件用 gpg 对称加密。我可以使用 for 循环来完成此操作,但更愿意通过管道来完成。

我尝试了以下方法,但由于“输入重定向不明确”而无法正常工作:

tar cvf /home/user/backupdir | xz -1 | gpg -c --batch --passphrase-fd 0 --yes --symmetric --cipher-algo TWOFISH --digest-algo SHA512 -o backupdir.tar.xz.gpg < keyfile

谁能帮我解决这个问题,通过管道进行加密和解密?

谢谢!

最佳答案

你基本上是在做:

tar | xz | gpg <file

在这个链中,您告诉 gpg 从文件和上一个命令中获取输入。

只有一个 STDIN,您无法从两个来源读取。

手册页给出了一些解决方案:

   --passphrase-fd n
Read the passphrase from file descriptor n. Only the first line will
be read from file descriptor n. If you use 0 for n, the passphrase
will be read from STDIN. This can only be used if only one
passphrase is supplied. Note that this passphrase is only used if
the option --batch has also been given. This is different from gpg.

--passphrase-file file
Read the passphrase from file file. Only the first line will be read
from file file. This can only be used if only one passphrase is sup‐
plied. Obviously, a passphrase stored in a file is of questionable
security if other users can read this file. Don't use this option if
you can avoid it. Note that this passphrase is only used if the
option --batch has also been given. This is different from gpg.

--passphrase string
Use string as the passphrase. This can only be used if only one
passphrase is supplied. Obviously, this is of very questionable
security on a multi-user system. Don't use this option if you can
avoid it. Note that this passphrase is only used if the option
--batch has also been given. This is different from gpg.

因为您已经在文件中有了密码,所以第二个选项看起来适合您。

如果第二个选项不可用或不适用于您的 gpg 版本,您可以改用第一个选项:

gpg --passphrase-fd 3 3<keyfile

在这种情况下,gpg 将获取 STDIN 上的数据和文件描述符 3 上的 key 文件。

关于linux - 具有三重管道和 key 文件的 GPG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22435660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com