unix - gpg : processing message failed: eof ;Error Unix ksh GPG decryption Script

标签 unix ksh gnupg

我是 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"

最佳答案

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

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

由于没有给出密码输入,gpg 尝试从控制台读取密码。现在会发生什么,取决于您的 gpg 配置、ksh 行为等,但我怀疑与 STDIN 的交互以某种方式瘫痪,导致 EOF 错误。

您的问题的解决方案:您必须将密码源添加到解密调用中:
echo "PASSPHRASE" | gpg --passphrase-fd 0 --output "$outputF" --decrypt "$encryptedF"

关于unix - gpg : processing message failed: eof ;Error Unix ksh GPG decryption Script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18068393/

相关文章:

c - 在 C 中通过 EOF 停止 While 循环

macos - Mac OS X 上的 POSIX 信号量 : sem_timedwait alternative

shell - 将 stderr 和 stdout 复制到文件以及 ksh 中的屏幕

shell - 在 unix shell 脚本中转义大括号

ssh - 如何在 NixOS 中使用 GnuPG 代理设置 SSH 关键字缓存?

encryption - GnuPG/PGP 和 SSL : Sharing the same private key?

unix - 如何使用腻子将文件从hdfs加载到本地服务器?

c - C 中的正则表达式 - 匹配组

linux - sed 命令不接受 ksh 中带有 '.' 的子字符串

encryption - 使用 GPG 解密不会创建输出文件