GnuPG,简称 GPG,来自 http://www.gnupg.org,是 GPG 标准的一个免费实现。不管是 Linux 还是 Windows 平台,都可以使用。GPGneng 可以为文件生成签名、管理密匙以及验证签名。
此 PECL 扩展未与 PHP 捆绑。
Here are instructions for how to resolve the issue where you encounter this error: /usr/include/gpgme.h:80:2: error: #error GPGME was compiled with _FILE_OFFSET_BITS = 64, please see the section "Largefile support (LFS)" in the GPGME manual. This is a result of the gnupg extension currently lacking largefile support. The solution is fairly simple. pecl download gnupg tar -zxf gnupg-1.3.2.tgz cd gnupg-1.3.2 Open the file config.m4 in an editor, and add "AC_SYS_LARGEFILE" to a new line at the very end of the file, then save. phpize ./configure make make install Now simply add extension=gnupg.so to your php.ini, and the extension should work.
I tried followings on Debian Squeeze and it worked fine apt-get install libgpgme11-dev pecl install gnupg create a new file under conf.d folder and add following lines ; configuration for gnupg module extension=gnupg.so Reload apache configuration /etc/init.d/apache2 reload Check PHP Info and you should see gnupg Hope this helps.
Example #1 gnupg clearsign example (procedural)
<?php // init gnupg $res = gnupg_init(); // not really needed. Clearsign is default gnupg_setsignmode($res,GNUPG_SIG_MODE_CLEAR); // add key with passphrase 'test' for signing gnupg_addsignkey($res,"8660281B6051D071D94B5B230549F9DC851566DC","test"); // sign $signed = gnupg_sign($res,"just a test"); echo $signed; ?>
Example #2 gnupg clearsign example (OO)
<?php // new class $gnupg = new gnupg(); // not really needed. Clearsign is default $gnupg->setsignmode(gnupg::SIG_MODE_CLEAR); // add key with passphrase 'test' for signing $gnupg->addsignkey("8660281B6051D071D94B5B230549F9DC851566DC","test"); // sign $signed = $gnupg->sign("just a test"); echo $signed; ?>
Example #3 keylistiterator
This extension also comes with an Iterator for your keyring.
<?php // create a new iterator for listing all public keys that matches 'example' $iterator = new gnupg_keylistiterator("example"); foreach($iterator as $fingerprint => $userid){ echo $fingerprint." -> ".$userid."\n"; } ?>