gpg: 处理消息失败: eof;Unix ksh GPG 解密脚本错误

4

我是Unix和ksh脚本编写的新手。我写了一个解密gpg消息的脚本。我遇到了这个错误,但不知道如何解决。我希望有人能看看我的脚本并帮助我找出问题所在。非常感谢您提供的任何帮助。以下是错误信息:

gpg: processing message failed: eof

这是我的脚本:

#!/bin/ksh
####################################################################       
#   1. Decrypt Inbound File                                        #
#                                                                  #
#   Two parms are required:   output file                          #
#                             encrypted file(to be decrypted)      #
#                                                                  #
####################################################################
# Variable declaration                                             #
####################################################################
outputF=$1 
encryptedF=$2
id=$$
####################################################################
# print_message                                                    #
#    prints messages to log file                                   #
####################################################################
print_message()
{
   message="$1"
   echo "`date '+%m-%d-%y %T'`  $message" 

}
#####################################################################
# Validate input parameters and existence of encrypted file         #
#####################################################################

if [ $1 -eq ""] ||  [ $2 -eq ""]
    then 
    print_message "Parameters not satisfied"

    exit 1 
fi 

if [ ! -f $encryptedF ]
then
   print_message "$id ERROR: $encryptedF File does not exist"
   exit 1
fi

#####################################################
#               Decrypt encryptedF                  #
#####################################################

gpg --output "$outputF" --decrypt "$encryptedF"

echo "PASSPHRASE" | gpg --passphrase-fd 0 

print_message "$id INFO: File Decrypted Successfully"

你写道:"我遇到一个错误,不知道该如何解决" ... 请编辑你的消息,包括错误信息的确切文本。正如你已经发现的那样,使用{}编辑工具来保持消息的格式。祝你好运。 - shellter
@shellter 更新了,你认为你能帮忙吗? - tacotuesday
请编辑您的问题以显示您正在执行的gpg行。所有其他代码看起来都很好,我会删除它,并发布一个简单的gpg测试用例。... 我不确定如何提供帮助,因为我对Unix进程的了解很有限,我希望您的两个命令被合并为一个,并且gpg的输出被发送到某个地方:像gpg ...> unecryptedFile这样的重定向文件,或者分配给shell变量,例如 myUnecryptedOutput=$(gpg ....)。您能否更新以包括使用一些简单输入短语的预期输出? 祝好运。 - shellter
1个回答

3

这不是一个gpg问题 :-) 您的脚本尝试两次运行gpg二进制文件。第一次调用尝试解码文件:

gpg --output "$outputF" --decrypt "$encryptedF"

由于没有提供输入口令的方式,因此gpg尝试从控制台读取口令。现在会发生什么取决于您的gpg配置、ksh行为等,但我怀疑与STDIN的交互被某种方式削弱,导致EOF错误。
解决方案:您需要将口令源添加到解密调用中。
echo "PASSPHRASE" | gpg --passphrase-fd 0 --output "$outputF" --decrypt "$encryptedF"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接