GPG Error Code 2

陌路散爱 提交于 2019-11-28 01:57:00

GPG is asking whether you want to continue on with the encryption using an unsigned key. Since no user can input Y it produces an error.

To fix this put the following switches

--yes and --always-trust

Thiago Silveira

See this message: http://lists.gnupg.org/pipermail/gnupg-users/2008-January/032410.html

It appears to be a permission problem. gpg is trying to access a directory that it can't have access to, so it fails with a fatal error. (error code 2)

You can fix that by specifying a homedir directive with a directory writable by gpg. Like this:

$cmd = "/usr/bin/gpg -a --recipient $to -e -o $outfile $infile --homedir /path/to/dir";

Information from man gpg:

--homedir directory
Set the name of the home directory to directory

If this option is not used it defaults to "~/.gnupg". It does not make sense to use this in a options file. This also overrides the environment variable $GNUPGHOME.

You also might want to concider adding key to trusted keys list:

gpg.exe --edit-key KEY_NAME
trust
5 (level of trust)
Y
Save

I've had some problems of --always-trust parameter not functioning properly on XP windows, this helped me solve the problem.

I had the same problem, but for the decoding command

At first and general, you can get the error message by redirecting stderr to stdout.

$cmd = "/usr/bin/gpg -a --recipient $to -e -o $outfile $infile 2>&1";

Then you can modify gpg's parameters to suit your needs. Because I had a files encrypted with a key with pass phrase I had to add several parameters.

I started with

gpg  -o $out -d $path

But it complained, that it can not open tty, then with --no-tty it outputs some other errors and finally the command for decoding files with key with pass phrase is

gpg --batch --passphrase $pass_phrase --no-tty -o $outfile -d $path_to_encoded_file

I hope this helps someone.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!