I recommend that the key may be generated in shell command line, then you export the keys using this group of commands.
gpg --export -a "User Name" > public.key
gpg --export-secret-key -a "User Name" > private.key
to use it, at the import and use it for encryption and decryption.
<?php
$GnuPG = new gnupg();
$PublicData = file_get_contents('public.key');
$PrivateData = file_get_contents('public.key');
$PublicKey = $GnuPG->import($PublicData);
$PrivateKey = $GnuPG->import($PrivateData);
echo 'Public Key : ',$PublicKey['fingerprint'],' & Private Key : ',$PrivateKey['fingerprint'];
?>