1. Go to this page and download the library: Download botdigit/completeopenpgp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
botdigit / completeopenpgp example snippets
return [
'key_storage' => storage_path('keys'), // Path where keys will be stored
'default_curve' => 'ed25519', // Default elliptic curve for signing
'signing_key' => env('PGP_SIGNING_KEY'), // PGP signing key (can be set in .env)
'encryption_key' => env('PGP_ENCRYPTION_KEY'), // PGP encryption key (can be set in .env)
'passphrase' => env('PGP_PASSPHRASE'), // Passphrase for private keys (if necessary)
];
use CompleteOpenPGP\Facades\CompleteOpenPGP;
$publicKey = file_get_contents(storage_path('keys/public_key.asc'));
$message = "Hello, this is a test message!";
$encryptedMessage = CompleteOpenPGP::encrypt($message, $publicKey);
use CompleteOpenPGP\Facades\CompleteOpenPGP;
$privateKey = file_get_contents(storage_path('keys/private_key.asc'));
$passphrase = env('PGP_PASSPHRASE');
$message = "This is a message I want to sign.";
$signedMessage = CompleteOpenPGP::sign($message, $privateKey, $passphrase);
use CompleteOpenPGP\Facades\CompleteOpenPGP;
$publicKey = file_get_contents(storage_path('keys/public_key.asc'));
$message = "This is a message I want to verify.";
$signature = '...'; // Signature from the signed message
$isValid = CompleteOpenPGP::verify($message, $signature, $publicKey);
if ($isValid) {
echo "The signature is valid!";
} else {
echo "The signature is invalid!";
}