Reputation: 11
I have a public key with extension .asc that I need to use to encrypt data and to send it in a plain text file. I am trying to accomplish this in a windows machine using php. Any ideas? Thanks,
Upvotes: 0
Views: 2125
Reputation: 2011
first create new folder owner by www-data
mkdir /var/www/.gnupg
sudo chown -R www-data:www-data /var/www/.gnupg
second try follow php code:
putenv("GNUPGHOME=/var/www/.gnupg");
$gpg = new gnupg();
$publicData = file_get_contents('/var/www/html/web/resources/keys/public.asc');
$privateData = file_get_contents('/var/www/html/web/resources/keys/SECRET.asc');
$publicKey = $gpg->import($publicData);
$gpg->addencryptkey($publicKey['fingerprint']);
$encrypt = ($gpg->encrypt('Data to encrypt'));
echo $encrypt;
Upvotes: 0
Reputation: 38722
Make sure you installed the gnupg extension for PHP.
$gpg = new gnupg();
$publicData = file_get_contents('public.asc');
$publicKey = $gpg->import($publicData);
$gpg->addencryptkey($publicKey['fingerprint']);
echo $gpg->encrypt('Data to encrypt');
Instead of encrypting a constant, replace by the file contents, and store the encrypted message wherever you want.
Upvotes: 1