cvs: peardoc /en/package encryption.xml /en/package/encryption crypt-gpg.xml /en/package/encryption/crypt-gpg examples.xml generate-key.xml
intro.xml referring-to-keys.xml
| From: | Michael Gauthier | Date: | Thu, 07 Aug 2008 13:21:52 +0000 |
| Subject: | cvs: peardoc /en/package encryption.xml /en/package/encryption crypt-gpg.xml /en/package/encryption/crypt-gpg examples.xml generate-key.xml intro.xml referring-to-keys.xml |
||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-11038@lists.php.net to get a copy of this message | ||
gauthierm Thu Aug 7 13:21:52 2008 UTC
Added files:
/peardoc/en/package/encryption crypt-gpg.xml
/peardoc/en/package/encryption/crypt-gpg examples.xml
generate-key.xml intro.xml
referring-to-keys.xml
Modified files:
/peardoc/en/package encryption.xml
Log:
Add documentation for Crypt_GPG. Fixes #13910.
http://cvs.php.net/viewvc.cgi/peardoc/en/package/encryption.xml?r1=1.6&r2=1.7&diff_format=u Index: peardoc/en/package/encryption.xml diff -u peardoc/en/package/encryption.xml:1.6 peardoc/en/package/encryption.xml:1.7 --- peardoc/en/package/encryption.xml:1.6 Fri Feb 17 16:04:31 2006 +++ peardoc/en/package/encryption.xml Thu Aug 7 13:21:52 2008 @@ -1,15 +1,17 @@ -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <chapter id="package.encryption"> <title>Encryption</title> <para> - Provides Packages for de- and encryption + Provides packages for encryption, decryption, signing, verifying and key + management. </para> &blankpagehack; - &package.encryption.crypt-chap; + &package.encryption.crypt-chap; + &package.encryption.crypt-gpg; </chapter> <!-- Keep this comment at the end of the file http://cvs.php.net/viewvc.cgi/peardoc/en/package/encryption/crypt-gpg.xml?view=markup&rev=1.1 Index: peardoc/en/package/encryption/crypt-gpg.xml +++ peardoc/en/package/encryption/crypt-gpg.xml <!-- $Revision: 1.1 $ --> <sect1 id="package.encryption.crypt-gpg"> <title>Crypt_GPG</title> &package.encryption.crypt-gpg.intro; &package.encryption.crypt-gpg.generate-key; &package.encryption.crypt-gpg.referring-to-keys; &package.encryption.crypt-gpg.examples; </sect1> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/encryption/crypt-gpg/examples.xml?view=markup&rev=1.1 Index: peardoc/en/package/encryption/crypt-gpg/examples.xml +++ peardoc/en/package/encryption/crypt-gpg/examples.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.encryption.crypt-gpg.examples"> <refnamediv> <refname>Examples</refname> <refpurpose>several small examples of Crypt_GPG's usage</refpurpose> </refnamediv> <!--refentryinfo> <author> <firstname>Michael</firstname> <surname>Gauthier</surname> </author> </refentryinfo--> <refsect1 id="package.encryption.crypt-gpg.examples.notes"> <title></title> <para> <note> <para> This documentation covers version 0.7.0 of Crypt_GPG which has an API that is still in beta. The code in these examples is subject to change. </para> </note> <note> <para> The following examples assume you have created a key following the <link linkend="package.encryption.crypt-gpg.generate-key">instructions for generating a key</link> that can both encrypt and sign data. The example key has a user id of <emphasis>test@example.com</emphasis> and a passphrase of <emphasis>test</emphasis>. All signature data is ficticious but is formatted like real signature data. </para> </note> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.signing-file"> <title>Signing a Package File</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; $data = file_get_contents($package_file_name); $passphrase = 'test'; $gpg = Crypt_GPG::factory(); $signature = $gpg->sign('test@example.com', $data, $passphrase, Crypt_GPG::SIGN_MODE_DETACHED); echo "Package signature is: ", $signature, "\n"; ?> ]]></programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.verifying-file"> <title>Verifying a Signed File</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; $signature = <<<DATA -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQBIl9Tf6ZWCktsVoskRAoAKAJ9VkbFDTSGY2ygaEGBcMOE8Or9puwCgppYm 0qq0bhtw5vsi0cJF5oC52RY= =VfxI -----END PGP SIGNATURE----- DATA; $signed_data = file_get_contents($package_file_name); $gpg = Crypt_GPG::factory(); $details = $gpg->verify($signed_data, $signature); if ($details->isValid()) { echo "Package is valid.\n"; } else { echo "Package is invalid!\n"; } ?> ]]></programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.encrypting-credit-card"> <title>Encrypting Credit Card Numbers</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; // ... connect to database ... $card_number = '411111111111'; $card_type = 'visa'; $gpg = Crypt_GPG::factory(); $encrypted = $gpg->encrypt('test@example.com', $card_number); $sql = sprintf('insert into payments (card_type, card_number) ' . 'values (%s, %s)', mysql_real_escape_string($card_type), mysql_real_escape_string($card_number)); mysql_exec($sql); ?> ]]></programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.decrypting-credit-card"> <title>Decrypting Credit Card Numbers</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; // ... connect to database ... $gpg = Crypt_GPG::factory(); $passphrase = 'test'; $sql = 'select card_type, card_number from payments'; $rs = mysql_query($sql); while ($row = mysql_fetch_object($rs)) { echo "Card type: ", $row->card_type, "\n"; echo "Card number: ", $gpg->decrypt($row->card_number, $passphrase); } ?> ]]></programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.publish-public-key"> <title>Publishing a Public Key</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; $gpg = Crypt_GPG::factory(); echo "My public key is: ", $gpg->exportPublicKey('test@example.com'), "\n"; echo "My key fingerprint is: ", $gpg->getFingerprint('test@example.com', Crypt_GPG::FORMAT_CANONICAL), "\n"; ?> ]]></programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.clearsign-message"> <title>Clearsigning a Message</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; $gpg = Crypt_GPG::factory(); $data = 'Hello, World!'; $passphrase = 'test'; $signed_data = $gpg->sign('test@example.com', $data, $passphrase, Crypt_GPG::SIGN_MODE_CLEAR); echo "Clearsigned message is: ", $signed_data, "\n"; ?> ]]></programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.verify-clearsign"> <title>Verifying a Clearsigned Message</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; $signed_data = <<<DATA -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, World! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFIl9Sb6ZWCktsVoskRArWDAJ9D5mq6p+4JnBy11OaAhnIA+uRSSACgoM5T WcUHQ9pKf9PvNUn1Izy6c9E= =k8+7 -----END PGP SIGNATURE----- DATA; $gpg = Crypt_GPG::factory(); $details = $gpg->verify($signed_data); if ($details->isValid()) { echo "Message is valid.\n"; } else { echo "Message is invalid!\n"; } ?> ]]></programlisting> </informalexample> </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/encryption/crypt-gpg/generate-key.xml?view=markup&rev=1.1 Index: peardoc/en/package/encryption/crypt-gpg/generate-key.xml +++ peardoc/en/package/encryption/crypt-gpg/generate-key.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.encryption.crypt-gpg.generate-key"> <refnamediv> <refname>Generating a GPG Key</refname> <refpurpose>outlines how to generate a GPG key for use with Crypt_GPG</refpurpose> </refnamediv> <!--refentryinfo> <author> <firstname>Michael</firstname> <surname>Gauthier</surname> </author> </refentryinfo--> <refsect1 id="package.encryption.crypt-gpg.generate-key.intro"> <title></title> <para> Crypt_GPG does not yet support generating GPG keys. Generating a GPG key for use with Crypt_GPG is much the same as generating any other GPG key on a system. </para> <para> <important> <para> Though Crypt_GPG supports specifying the keyring to use <!-- TODO: link to options -->, Crypt_GPG, by default, uses the keyring of the current user. If using Crypt_GPG with a webserver such as Apache, the current user is the Apache user and the key will need to be generated as the Apache user. To do this, run the gen-key command as: <informalexample> <programlisting> <command>$ sudo -u apache gpg --gen-key</command> </programlisting> </informalexample> </para> </important> </para> <para> The following example walks through the process of generating a key that supports both encrypting and signing. First, run the command: <programlisting> <command>$ gpg --gen-key</command> </programlisting> </para> <para> This will display the following copyright information and a list of available key types: <programlisting> gpg (GnuPG) 1.4.6; Copyright (C) 2006 Free Software Foundation, Inc. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the file COPYING for details. Please select what kind of key you want: (1) DSA and Elgamal (default) (2) DSA (sign only) (5) RSA (sign only) Your selection? 1 DSA keypair will have 1024 bits. </programlisting> </para> <para> Select <emphasis>(1) DSA and Elgamal (default)</emphasis> to allow the generated key to both encrypt and sign data. This will generate a public-private key pair in the GPG keyring and prompt for the size of the encryption key: <programlisting> ELG-E keys may be between 1024 and 4096 bits long. What keysize do you want? (2048) </programlisting> </para> <para> Select the default value of 2048. Enter greater or fewer bits depending on how secure the encryption must be. The default value is considered safe for most applications. GPG then prompts for the time period over which the generated key will be valid: <programlisting> Please specify how long the key should be valid. 0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years Key is valid for? (0) Key does not expire at all Is this correct? (y/N) y </programlisting> </para> <para> Unless the key needs to expire after a certain time period (preventing subsequent decryption), a key that does not expire should be used. Next, enter the three parts of the key's user id. The first part of the user id is the real name of the person or organization that will use the key to sign or encrypt data. The second part is an email address and the third is a comment about the key. Both the email address and comment are optional: <programlisting> You need a user ID to identify your key; the software constructs the user ID from the Real Name, Comment and Email Address in this form: "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>" Real name: Test User Email address: test@example.com Comment: test key Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o </programlisting> </para> <para> After entering the primary user id of the new key, the passphrase must be selected. A secret passphrase is essential to securing encrypted data. Guessable passphrases will render encryption useless. For critical data such as credit card numbers, a non-dictionary word that is at least 8 characters long is recommended. <programlisting> You need a Passphrase to protect your secret key. Enter passphrase: Repeat passphrase: </programlisting> </para> <para> Following the passphrase, GPG will gather entropy for a period to ensure the generated key uses sutitably random numbers. When enough entropy is collected the key is generated and added to the keyring: <programlisting> We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. .... snip ... gpg: key DB15A2C9 marked as ultimately trusted public and secret key created and signed. gpg: checking the trustdb gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u pub 1024D/DB15A2C9 2008-08-05 Key fingerprint = F94A F628 5725 7147 0569 F9FF E995 8292 DB15 A2C9 uid Test User (test key) <test@example.com> sub 2048g/6AD96F48 2008-08-05 </programlisting> </para> <para> At this point the key is in the GPG keyring and ready to be used by Crypt_GPG. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/encryption/crypt-gpg/intro.xml?view=markup&rev=1.1 Index: peardoc/en/package/encryption/crypt-gpg/intro.xml +++ peardoc/en/package/encryption/crypt-gpg/intro.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.encryption.crypt-gpg.intro"> <refnamediv> <refname>Introduction and Overview</refname> <refpurpose>introduces the Crypt_GPG package</refpurpose> </refnamediv> <!--refentryinfo> <author> <firstname>Michael</firstname> <surname>Gauthier</surname> </author> </refentryinfo--> <refsect1 id="package.encryption.crypt-gpg.intro.intro"> <title>Introduction</title> <para> Crypt_GPG is a PHP package to interact with the <ulink url="http://www.gnupg.org/">GNU Privacy Guard (GPG)</ulink>. GPG is a free and open-source implementation of the <ulink url="http://www.ietf.org/rfc/rfc4880.txt">OpenPGP protocol</ulink>, providing key managment, data encryption and data signing. Crypt_GPG provides an object-oriented API for performing OpenPGP commands using GPG. </para> <para> GPG is distributed as an executable program with a command line argument syntax for performing commands. Crypt_GPG uses PHP's <ulink url="http://ca3.php.net/manual/en/ref.exec.php">program execution functions</ulink> to run GPG as a subprocess thus performing the desired command. Crypt_GPG automatically handles process control, stream handling and error checking of the GPG subprocess. Crypt_GPG uses PHP streams internally for most actions, allowing (among other things) any streamable resource to be used with the Crypt_GPG file commands. </para> <para> <note> <para> Though GPG can support symmetric-key cryptography, this package is intended only to facilitate public-key cryptography. </para> </note> </para> </refsect1> <refsect1> <title>Overview</title> <para> The basic internal overview of a GPG command executed in Crypt_GPG is as follows: <orderedlist> <listitem> <para>build the required command line,</para> </listitem> <listitem> <para>open the GPG subprocess with the command line,</para> </listitem> <listitem> <para> stream data to and from the GPG subprocess on various IPC pipes until the command is finished, </para> </listitem> <listitem> <para>close the GPG subprocess and,</para> </listitem> <listitem> <para>check for errors.</para> </listitem> </orderedlist> </para> <para> Crypt_GPG handles all these details internally so GPG can be used with minimal effort from the developer. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/encryption/crypt-gpg/referring-to-keys.xml?view=markup&rev=1.1 Index: peardoc/en/package/encryption/crypt-gpg/referring-to-keys.xml +++ peardoc/en/package/encryption/crypt-gpg/referring-to-keys.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.encryption.crypt-gpg.referring-to-keys"> <refnamediv> <refname>Referring to Keys</refname> <refpurpose>outlines how to refer to GPG keys in code using Crypt_GPG</refpurpose> </refnamediv> <!--refentryinfo> <author> <firstname>Michael</firstname> <surname>Gauthier</surname> </author> </refentryinfo--> <refsect1 id="package.encryption.crypt-gpg.referring-to-keys.fingerprint"> <title>Fingerprint</title> <para> Crypt_GPG supports referring to a key in several ways. The most definitive way to refer to a specific key is to use the key's fingerprint. Key fingerprints are generated by performing a checksum on the actual content of a key. A fingerprint appears as a string of hex characters that may sometimes be separated by spaces or colons. For example: <emphasis>F94A F628 5725 7147 0569 F9FF E995 8292 DB15 A2C9</emphasis>. The fingerprint of a key can be retrieved using the <function>Crypt_GPG::getKeys</function> and <function>Crypt_GPG::getFingerprint</function> methods. Alternatively, the following command may be used to list keys on a console: <informalexample> <programlisting> <command>$ gpg --list-keys --with-fingerprint --with-fingerprint</command> </programlisting> </informalexample> <note> <para> <command>--with-fingerprint</command> is doubled intentionally. </para> </note> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.referring-to-keys.id"> <title>Key ID</title> <para> Keys may also be referenced by the key id. The key id is an eight-octal long hexidecimal number. The key id can be obtained using <function>Crypt_GPG::getKeys</function>. Though rare, it is possible to have two keys with the same key id. The key id may also be obtained using the following command: <informalexample> <programlisting> <command>$ gpg --list-keys --with-colons</command> </programlisting> </informalexample> The key id is the fifth colon-separated field. A partial key id may also be used to reference a key. The partial key id is the lower four octals of a full key id and may be obtained using the following command: <informalexample> <programlisting> <command>$ gpg --list-keys</command> </programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.referring-to-keys.user-id"> <title>User ID</title> <para> Lastly, keys may be referenced by all or part of the key's user id. For example, <emphasis>Test User (test key) <test@example.com></emphasis>, <emphasis>Test User <test@example.com></emphasis> and <emphasis>test@example.com</emphasis> may all be used to refer to the same key. When there is more than on key in the keyring with the same user id (or partial user id), the first key is used. In these cases, it is important to use a more specific identifier to ensure the correct key is used. In general, unless the keyring contains many keys, the less specific but more convenient form of <emphasis>test@example.com</emphasis> is fine to use. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
http://cvs.php.net/viewvc.cgi/peardoc/en/package/encryption.xml?r1=1.6&r2=1.7&diff_format=u Index: peardoc/en/package/encryption.xml diff -u peardoc/en/package/encryption.xml:1.6 peardoc/en/package/encryption.xml:1.7 --- peardoc/en/package/encryption.xml:1.6 Fri Feb 17 16:04:31 2006 +++ peardoc/en/package/encryption.xml Thu Aug 7 13:21:52 2008 @@ -1,15 +1,17 @@ -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <chapter id="package.encryption"> <title>Encryption</title> <para> - Provides Packages for de- and encryption + Provides packages for encryption, decryption, signing, verifying and key + management. </para> &blankpagehack; - &package.encryption.crypt-chap; + &package.encryption.crypt-chap; + &package.encryption.crypt-gpg; </chapter> <!-- Keep this comment at the end of the file http://cvs.php.net/viewvc.cgi/peardoc/en/package/encryption/crypt-gpg.xml?view=markup&rev=1.1 Index: peardoc/en/package/encryption/crypt-gpg.xml +++ peardoc/en/package/encryption/crypt-gpg.xml <!-- $Revision: 1.1 $ --> <sect1 id="package.encryption.crypt-gpg"> <title>Crypt_GPG</title> &package.encryption.crypt-gpg.intro; &package.encryption.crypt-gpg.generate-key; &package.encryption.crypt-gpg.referring-to-keys; &package.encryption.crypt-gpg.examples; </sect1> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/encryption/crypt-gpg/examples.xml?view=markup&rev=1.1 Index: peardoc/en/package/encryption/crypt-gpg/examples.xml +++ peardoc/en/package/encryption/crypt-gpg/examples.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.encryption.crypt-gpg.examples"> <refnamediv> <refname>Examples</refname> <refpurpose>several small examples of Crypt_GPG's usage</refpurpose> </refnamediv> <!--refentryinfo> <author> <firstname>Michael</firstname> <surname>Gauthier</surname> </author> </refentryinfo--> <refsect1 id="package.encryption.crypt-gpg.examples.notes"> <title></title> <para> <note> <para> This documentation covers version 0.7.0 of Crypt_GPG which has an API that is still in beta. The code in these examples is subject to change. </para> </note> <note> <para> The following examples assume you have created a key following the <link linkend="package.encryption.crypt-gpg.generate-key">instructions for generating a key</link> that can both encrypt and sign data. The example key has a user id of <emphasis>test@example.com</emphasis> and a passphrase of <emphasis>test</emphasis>. All signature data is ficticious but is formatted like real signature data. </para> </note> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.signing-file"> <title>Signing a Package File</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; $data = file_get_contents($package_file_name); $passphrase = 'test'; $gpg = Crypt_GPG::factory(); $signature = $gpg->sign('test@example.com', $data, $passphrase, Crypt_GPG::SIGN_MODE_DETACHED); echo "Package signature is: ", $signature, "\n"; ?> ]]></programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.verifying-file"> <title>Verifying a Signed File</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; $signature = <<<DATA -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQBIl9Tf6ZWCktsVoskRAoAKAJ9VkbFDTSGY2ygaEGBcMOE8Or9puwCgppYm 0qq0bhtw5vsi0cJF5oC52RY= =VfxI -----END PGP SIGNATURE----- DATA; $signed_data = file_get_contents($package_file_name); $gpg = Crypt_GPG::factory(); $details = $gpg->verify($signed_data, $signature); if ($details->isValid()) { echo "Package is valid.\n"; } else { echo "Package is invalid!\n"; } ?> ]]></programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.encrypting-credit-card"> <title>Encrypting Credit Card Numbers</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; // ... connect to database ... $card_number = '411111111111'; $card_type = 'visa'; $gpg = Crypt_GPG::factory(); $encrypted = $gpg->encrypt('test@example.com', $card_number); $sql = sprintf('insert into payments (card_type, card_number) ' . 'values (%s, %s)', mysql_real_escape_string($card_type), mysql_real_escape_string($card_number)); mysql_exec($sql); ?> ]]></programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.decrypting-credit-card"> <title>Decrypting Credit Card Numbers</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; // ... connect to database ... $gpg = Crypt_GPG::factory(); $passphrase = 'test'; $sql = 'select card_type, card_number from payments'; $rs = mysql_query($sql); while ($row = mysql_fetch_object($rs)) { echo "Card type: ", $row->card_type, "\n"; echo "Card number: ", $gpg->decrypt($row->card_number, $passphrase); } ?> ]]></programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.publish-public-key"> <title>Publishing a Public Key</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; $gpg = Crypt_GPG::factory(); echo "My public key is: ", $gpg->exportPublicKey('test@example.com'), "\n"; echo "My key fingerprint is: ", $gpg->getFingerprint('test@example.com', Crypt_GPG::FORMAT_CANONICAL), "\n"; ?> ]]></programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.clearsign-message"> <title>Clearsigning a Message</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; $gpg = Crypt_GPG::factory(); $data = 'Hello, World!'; $passphrase = 'test'; $signed_data = $gpg->sign('test@example.com', $data, $passphrase, Crypt_GPG::SIGN_MODE_CLEAR); echo "Clearsigned message is: ", $signed_data, "\n"; ?> ]]></programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.examples.verify-clearsign"> <title>Verifying a Clearsigned Message</title> <para> <informalexample> <programlisting role="php"><![CDATA[ <?php require_once 'Crypt/GPG.php'; $signed_data = <<<DATA -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, World! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFIl9Sb6ZWCktsVoskRArWDAJ9D5mq6p+4JnBy11OaAhnIA+uRSSACgoM5T WcUHQ9pKf9PvNUn1Izy6c9E= =k8+7 -----END PGP SIGNATURE----- DATA; $gpg = Crypt_GPG::factory(); $details = $gpg->verify($signed_data); if ($details->isValid()) { echo "Message is valid.\n"; } else { echo "Message is invalid!\n"; } ?> ]]></programlisting> </informalexample> </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/encryption/crypt-gpg/generate-key.xml?view=markup&rev=1.1 Index: peardoc/en/package/encryption/crypt-gpg/generate-key.xml +++ peardoc/en/package/encryption/crypt-gpg/generate-key.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.encryption.crypt-gpg.generate-key"> <refnamediv> <refname>Generating a GPG Key</refname> <refpurpose>outlines how to generate a GPG key for use with Crypt_GPG</refpurpose> </refnamediv> <!--refentryinfo> <author> <firstname>Michael</firstname> <surname>Gauthier</surname> </author> </refentryinfo--> <refsect1 id="package.encryption.crypt-gpg.generate-key.intro"> <title></title> <para> Crypt_GPG does not yet support generating GPG keys. Generating a GPG key for use with Crypt_GPG is much the same as generating any other GPG key on a system. </para> <para> <important> <para> Though Crypt_GPG supports specifying the keyring to use <!-- TODO: link to options -->, Crypt_GPG, by default, uses the keyring of the current user. If using Crypt_GPG with a webserver such as Apache, the current user is the Apache user and the key will need to be generated as the Apache user. To do this, run the gen-key command as: <informalexample> <programlisting> <command>$ sudo -u apache gpg --gen-key</command> </programlisting> </informalexample> </para> </important> </para> <para> The following example walks through the process of generating a key that supports both encrypting and signing. First, run the command: <programlisting> <command>$ gpg --gen-key</command> </programlisting> </para> <para> This will display the following copyright information and a list of available key types: <programlisting> gpg (GnuPG) 1.4.6; Copyright (C) 2006 Free Software Foundation, Inc. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the file COPYING for details. Please select what kind of key you want: (1) DSA and Elgamal (default) (2) DSA (sign only) (5) RSA (sign only) Your selection? 1 DSA keypair will have 1024 bits. </programlisting> </para> <para> Select <emphasis>(1) DSA and Elgamal (default)</emphasis> to allow the generated key to both encrypt and sign data. This will generate a public-private key pair in the GPG keyring and prompt for the size of the encryption key: <programlisting> ELG-E keys may be between 1024 and 4096 bits long. What keysize do you want? (2048) </programlisting> </para> <para> Select the default value of 2048. Enter greater or fewer bits depending on how secure the encryption must be. The default value is considered safe for most applications. GPG then prompts for the time period over which the generated key will be valid: <programlisting> Please specify how long the key should be valid. 0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years Key is valid for? (0) Key does not expire at all Is this correct? (y/N) y </programlisting> </para> <para> Unless the key needs to expire after a certain time period (preventing subsequent decryption), a key that does not expire should be used. Next, enter the three parts of the key's user id. The first part of the user id is the real name of the person or organization that will use the key to sign or encrypt data. The second part is an email address and the third is a comment about the key. Both the email address and comment are optional: <programlisting> You need a user ID to identify your key; the software constructs the user ID from the Real Name, Comment and Email Address in this form: "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>" Real name: Test User Email address: test@example.com Comment: test key Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o </programlisting> </para> <para> After entering the primary user id of the new key, the passphrase must be selected. A secret passphrase is essential to securing encrypted data. Guessable passphrases will render encryption useless. For critical data such as credit card numbers, a non-dictionary word that is at least 8 characters long is recommended. <programlisting> You need a Passphrase to protect your secret key. Enter passphrase: Repeat passphrase: </programlisting> </para> <para> Following the passphrase, GPG will gather entropy for a period to ensure the generated key uses sutitably random numbers. When enough entropy is collected the key is generated and added to the keyring: <programlisting> We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. .... snip ... gpg: key DB15A2C9 marked as ultimately trusted public and secret key created and signed. gpg: checking the trustdb gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u pub 1024D/DB15A2C9 2008-08-05 Key fingerprint = F94A F628 5725 7147 0569 F9FF E995 8292 DB15 A2C9 uid Test User (test key) <test@example.com> sub 2048g/6AD96F48 2008-08-05 </programlisting> </para> <para> At this point the key is in the GPG keyring and ready to be used by Crypt_GPG. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/encryption/crypt-gpg/intro.xml?view=markup&rev=1.1 Index: peardoc/en/package/encryption/crypt-gpg/intro.xml +++ peardoc/en/package/encryption/crypt-gpg/intro.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.encryption.crypt-gpg.intro"> <refnamediv> <refname>Introduction and Overview</refname> <refpurpose>introduces the Crypt_GPG package</refpurpose> </refnamediv> <!--refentryinfo> <author> <firstname>Michael</firstname> <surname>Gauthier</surname> </author> </refentryinfo--> <refsect1 id="package.encryption.crypt-gpg.intro.intro"> <title>Introduction</title> <para> Crypt_GPG is a PHP package to interact with the <ulink url="http://www.gnupg.org/">GNU Privacy Guard (GPG)</ulink>. GPG is a free and open-source implementation of the <ulink url="http://www.ietf.org/rfc/rfc4880.txt">OpenPGP protocol</ulink>, providing key managment, data encryption and data signing. Crypt_GPG provides an object-oriented API for performing OpenPGP commands using GPG. </para> <para> GPG is distributed as an executable program with a command line argument syntax for performing commands. Crypt_GPG uses PHP's <ulink url="http://ca3.php.net/manual/en/ref.exec.php">program execution functions</ulink> to run GPG as a subprocess thus performing the desired command. Crypt_GPG automatically handles process control, stream handling and error checking of the GPG subprocess. Crypt_GPG uses PHP streams internally for most actions, allowing (among other things) any streamable resource to be used with the Crypt_GPG file commands. </para> <para> <note> <para> Though GPG can support symmetric-key cryptography, this package is intended only to facilitate public-key cryptography. </para> </note> </para> </refsect1> <refsect1> <title>Overview</title> <para> The basic internal overview of a GPG command executed in Crypt_GPG is as follows: <orderedlist> <listitem> <para>build the required command line,</para> </listitem> <listitem> <para>open the GPG subprocess with the command line,</para> </listitem> <listitem> <para> stream data to and from the GPG subprocess on various IPC pipes until the command is finished, </para> </listitem> <listitem> <para>close the GPG subprocess and,</para> </listitem> <listitem> <para>check for errors.</para> </listitem> </orderedlist> </para> <para> Crypt_GPG handles all these details internally so GPG can be used with minimal effort from the developer. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/encryption/crypt-gpg/referring-to-keys.xml?view=markup&rev=1.1 Index: peardoc/en/package/encryption/crypt-gpg/referring-to-keys.xml +++ peardoc/en/package/encryption/crypt-gpg/referring-to-keys.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.encryption.crypt-gpg.referring-to-keys"> <refnamediv> <refname>Referring to Keys</refname> <refpurpose>outlines how to refer to GPG keys in code using Crypt_GPG</refpurpose> </refnamediv> <!--refentryinfo> <author> <firstname>Michael</firstname> <surname>Gauthier</surname> </author> </refentryinfo--> <refsect1 id="package.encryption.crypt-gpg.referring-to-keys.fingerprint"> <title>Fingerprint</title> <para> Crypt_GPG supports referring to a key in several ways. The most definitive way to refer to a specific key is to use the key's fingerprint. Key fingerprints are generated by performing a checksum on the actual content of a key. A fingerprint appears as a string of hex characters that may sometimes be separated by spaces or colons. For example: <emphasis>F94A F628 5725 7147 0569 F9FF E995 8292 DB15 A2C9</emphasis>. The fingerprint of a key can be retrieved using the <function>Crypt_GPG::getKeys</function> and <function>Crypt_GPG::getFingerprint</function> methods. Alternatively, the following command may be used to list keys on a console: <informalexample> <programlisting> <command>$ gpg --list-keys --with-fingerprint --with-fingerprint</command> </programlisting> </informalexample> <note> <para> <command>--with-fingerprint</command> is doubled intentionally. </para> </note> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.referring-to-keys.id"> <title>Key ID</title> <para> Keys may also be referenced by the key id. The key id is an eight-octal long hexidecimal number. The key id can be obtained using <function>Crypt_GPG::getKeys</function>. Though rare, it is possible to have two keys with the same key id. The key id may also be obtained using the following command: <informalexample> <programlisting> <command>$ gpg --list-keys --with-colons</command> </programlisting> </informalexample> The key id is the fifth colon-separated field. A partial key id may also be used to reference a key. The partial key id is the lower four octals of a full key id and may be obtained using the following command: <informalexample> <programlisting> <command>$ gpg --list-keys</command> </programlisting> </informalexample> </para> </refsect1> <refsect1 id="package.encryption.crypt-gpg.referring-to-keys.user-id"> <title>User ID</title> <para> Lastly, keys may be referenced by all or part of the key's user id. For example, <emphasis>Test User (test key) <test@example.com></emphasis>, <emphasis>Test User <test@example.com></emphasis> and <emphasis>test@example.com</emphasis> may all be used to refer to the same key. When there is more than on key in the keyring with the same user id (or partial user id), the first key is used. In these cases, it is important to use a more specific identifier to ensure the correct key is used. In general, unless the keyring contains many keys, the less specific but more convenient form of <emphasis>test@example.com</emphasis> is fine to use. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->