2012-03-16 30 views
1

我正在为一个gpg问题挣扎几天,无法找到我自己的解决方案。我会很高兴,如果你可以帮我解决以下问题:GPG解密没有内容的文件/为空文件

我需要在php中解密一个gpg文件。为此,我使用以下命令:

cat passphrase.txt | /usr/local/bin/gpg --decrypt --passphrase-fd 0 stammdaten.txt.gpg>stammdaten.txt 

the passphrase.txt contains the password for decryption 
stammdaten.txt.gpg is the encrypted file 
the decrypted data will be written in stammdaten.txt 

when i run this command in php: 


shell_exec=("cat passphrase.txt | /usr/local/bin/gpg --decrypt --passphrase-fd 0 stammdaten.txt.gpg>stammdaten.txt") 


i get a zero-byte output file (stammdaten.txt) with owner=ftpadmin and group=psacln 

but when i execute the same command via ssh terminal (as root), the data will be decrypted and written correctly with file owner=root and group=root. 

我认为,这是一个权限问题。我怎样才能在PHP中正确使用该命令?我也尝试用ftprightson解密文件chown和chgrp,但似乎没有任何帮助。

每个答案都非常感谢。谢谢!

回答

1

我终于得到它的工作:

首先,我改变了GPG命令解密与呼应的密码进入标准输入:

$passphrase = utf8_decode('mypassphrase'); 
$encrypted = 'fullsystempathtogpgfile.gpg'; 

"echo '$passphrase' | /usr/local/bin/gpg -v -v --batch --passphrase-fd 0 --no-default-keyring $encrypted"; 

用了shell_exec我需要执行前改变gpg的homedir:

它被设置之前:

putenv("GNUPGHOME=/var/www/.gnupg"); 

但很明显,php用户(在我的情况下“ftpadmin”,发现与“whoami”)没有权限访问该目录,所以我复制.gpg文件夹到我的新创建的PHP用户文件夹:/ home/ftpadmin(777个烫发),并改变了GNUPGHOME:

putenv("GNUPGHOME=/home/ftpadmin/.gnupg"); 

现在我能够解密用PHP GPG文件。也许你可以为你的类似问题找到一些帮助。再次感谢每一个答案。

0

你可以尝试使用

cat passphrase.txt | /usr/local/bin/gpg --output stammdaten.txt --decrypt --passphrase-fd 0 stammdaten.txt.gpg 

代替。

你可以尝试的另一件事是在你的stammdaten.txt文件所在的目录中以ftpadmin的身份在shell中运行此命令,以确保它不是文件权限问题。

su ftpadmin 
cat passphrase.txt | /usr/local/bin/gpg --output stammdaten.txt --decrypt --passphrase-fd 0 stammdaten.txt.gpg 
+0

如果我尝试你的建议命令,我得到gpg:无效选项“--passphrase-fd0”,如果我尝试“su ftpadmin”没有任何反应,我仍然以root身份登录。但是当我“苏www数据”我切换并执行我的初始命令。文件所有者和组则是“www-data”,文件写入成功。是否有可能执行我的命令作为万维网数据? – user963942 2012-03-19 12:31:17

+0

无效选项问题是我的错......该命令在shell中工作,但不在shell中的shell_exec中。 – user963942 2012-03-19 13:59:39