3 require_once dirname(__FILE__).'/../lib/openpgp.php';
4 require_once dirname(__FILE__).'/../lib/openpgp_crypt_rsa.php';
6 /* Parse secret key from STDIN, the key must not be password protected */
7 $wkey = OpenPGP_Message::parse(file_get_contents('php://stdin'));
10 $string = "This\nis\na\ntest.";
12 /* Create a new literal data packet */
13 $data = new OpenPGP_LiteralDataPacket($string, array('format' => 'u', 'filename' => 'stuff.txt'));
14 $data->normalize(true); // Clearsign-style normalization of the LiteralDataPacket
16 /* Create a signer from the key */
17 $sign = new OpenPGP_Crypt_RSA($wkey);
19 /* The message is the signed data packet */
20 $m = $sign->sign($data);
22 /* Generate clearsigned data */
23 $packets = $m->signatures()[0];
24 echo "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA256\n\n";
25 // Output normalised data. You could convert line endings here
26 // without breaking the signature, but do not add any
27 // trailing whitespace to lines.
28 echo preg_replace("/^-/", "- -", $packets[0]->data)."\n";
29 echo OpenPGP::enarmor($packets[1][0]->to_bytes(), "PGP SIGNATURE");