<?php $plaintext_body = 'Some sensitive order data'; $recipient = '*****@*****.**'; $g = gnupg_init(); gnupg_seterrormode($g, GNUPG_ERROR_WARNING); // Fingerprint of the recipient's key $a = gnupg_addencryptkey($g, "5495F0CA9C8F30A9274C2259D7EBE8584CEF302B"); // Fingerprint of the sender's key $b = gnupg_addsignkey($g, "520D5FC5C85EF4F4F9D94E1C1AF1F7C5916FC221", "passphrase"); $encrypted_body = gnupg_encryptsign($g, $plaintext_body); mail($recipient, 'Web Site Order', $encrypted_body);
/** * Sign the chunk provided as with the specified key * * @param $data The data as a string blob * @param $keyfp The key fingerprint * @return The signature */ static function sign($keyfp) { $gp = gnupg_init(); gnupg_addsignkey($gp, $keyfb); gnupg_setsignmode($gp, GNUPG_SIG_MODE_DETACH); $signature = gnupg_sign($gp, $this->data); return $signature; }
<?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;