Ask Your Question
1

In PHP, what are the steps to encrypt/decrypt a PGP file?

asked 2023-06-07 19:33:25 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-07 19:38:02 +0000

lalupa gravatar image

To encrypt/decrypt a PGP file in PHP, you can follow these steps:

  1. Install the GnuPG extension for PHP using Composer:
composer require php-gnupg/php-gnupg
  1. Load the GnuPG module:
$gpg = new gnupg();
  1. Set the path to the GnuPG executable:
$gpg->seterrormode(gnupg::ERROR_EXCEPTION);
$gpg->setarmor(1);
$gpg->setbinmode(gnupg::BINMODE_ASCII);
$gpg->addencryptkey($recipient_fingerprint);
$gpg->setpassphrase($passphrase);
$encrypted_data = $gpg->encrypt($data);
  1. Decrypt the file:
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_EXCEPTION);
$gpg->setarmor(1);
$gpg->setbinmode(gnupg::BINMODE_ASCII);
$gpg->adddecryptkey($recipient_fingerprint, $recipient_passphrase);
$decrypted_data = $gpg->decrypt($encrypted_data);
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-07 19:33:25 +0000

Seen: 16 times

Last updated: Jun 07 '23