// 若要產生金鑰,請在命令列中輸入 gpg --gen-key
// 若要匯出公開金鑰,請輸入 gpg --export -a "使用者名稱" > public.key
<?php
putenv("GNUPGHOME=/tmp");
// 假設公開金鑰存在於 /tmp/keys 資料夾中
$publicKey = file_get_contents(getenv('GNUPGHOME') . '/keys/public.key');
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_EXCEPTION);
$info = $gpg->import($publicKey);
$gpg->addencryptkey($info['fingerprint']);
$uploadFileContent = file_get_contents('/tmp/file-to-encrypt');
$enc = $gpg->encrypt($uploadFileContent);
echo $enc
希望這有幫助