note 126431 deleted from function.gnupg-decrypt by cmb
| From: | cmb@php.net | Date: | Fri, 17 Sep 2021 20:27:07 +0000 |
| Subject: | note 126431 deleted from function.gnupg-decrypt by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216969@lists.php.net to get a copy of this message | ||
Note Submitter: ricardobarbosams
----
Hi, I'm using code bellow to encrypt and decrypt and works, only test:
```
<?php
$CONFIG['gnupg_home'] = '/var/www/.gnupg';
$CONFIG['gnupg_fingerprint'] = 'XXXXXXXXXXXXXXXXXXX';
$passphrase = '123456';
$data = 'Its a test';
echo "Original: $data<br>";
$gpg = new gnupg();
putenv("GNUPGHOME={$CONFIG['gnupg_home']}");
$gpg->seterrormode(GNUPG_ERROR_WARNING);
$gpg->addencryptkey($CONFIG['gnupg_fingerprint']);
$encrypted = $gpg->encrypt($data);
echo "Text Encrypt: \n<pre>$encrypted</pre>\n<br>";
$gpg->adddecryptkey($CONFIG['gnupg_fingerprint'], $passphrase);
$decrypted = $gpg->decrypt($encrypted);
echo $gpg->geterror();
echo "<br>\nText Descrypt: $decrypted\n";
?>
```
But when I generate an encrypted file and try to decrypt it with the code below it doesn't
work.
```
<?php
$CONFIG['gnupg_home'] = '/var/www/.gnupg';
$CONFIG['gnupg_fingerprint'] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$passphrase = '123456';
$encrypted = "./abacate.txt.gpg";
$gpg = new gnupg();
putenv("GNUPGHOME={$CONFIG['gnupg_home']}");
$gpg->seterrormode(GNUPG_ERROR_SILENT);
$gpg->addencryptkey($CONFIG['gnupg_fingerprint']);
$gpg->adddecryptkey($CONFIG['gnupg_fingerprint'], $passphrase);
$text = file_get_contents($encrypted);
var_dump($text);
$decrypted = $gpg->decrypt($text);
echo $gpg->geterror();
echo "\nDescrypt text: $decrypted\n";
?>
```
I gave apache user permission and 700 permission to the /var/www/.gnupg directory and it still
doesn't work has anyone experienced this?
It displays the message
decrypt failed