I've run into issues with getting the various GnuPG email creation modules available to work. It looks like it is some change from GnuPG 1 to GnuPG 2. So I set out to write one out two simple functions to do this using MIME::Lite. One creates a email and one signs the body, if needed.

1: The creation function is invoked and checks if it it needs to use PGP.
2: If it is to use PGP, it passes the body to the signing function.
3: The signing function takes it and processes the body as follows...

$body="Content-Disposition: inline\n". "Content-Transfer-Encoding: quoted-printable\n". "Content-Type: text/plain\n\n".encode_qp($body);

As the headers for the MIME section are required to be signed as well as the data, the headers that will be added later are tacked on in the form that MIME::Lite will use.

'encode_qp' is from 'MIME::QuotedPrint'.
4: This is then writen to the file and 'gpg2 -u '.$key.' --digest-algo SHA512 -a --detach-sign '.$bodyfile is ran.
5: $bodyfile.'asc' is then read in and returned the the creation function.
6: The email is then constructed...
$email=MIME::Lite->new(Type=>'multipart/signed');<br> $email->attr('content-type.protocol'=>'application/pgp-signature'); $email->attr('content-type.micalg'=>'PGP-SHA512'); $email->attach('Content-Type'=>'text/plain', Encoding=>'quoted-printab +le', Data=>$body); $email->attach(Type=>'application/pgp-signature', Filename=>'signature +.asc', Disposition=>'attachment', Encoding=>'7bit',Data=>$signed); $email->add('To'=>$to); $email->add('From'=>$from); $email->add('From'=>$subject);
8: The resulting object is then returned.

Please see the following for a example resulting string...
MIME-Version: 1.0 Content-Transfer-Encoding: binary Content-Type: multipart/signed; boundary="_----------=_123721441885025 +0"; micalg="PGP-SHA512"; protocol="application/pgp-signature" X-Mailer: MIME::Lite 3.024 (F2.77; T1.27; A2.04; B3.07; Q3.07) Date: Mon, 16 Mar 2009 09:40:18 -0500 To: vvelox@vvelox.net Subject: subject From: v.velox@vvelox.net Message-Id: <0.564867957585143.1237214418.ZConf::Mail@vixen42> This is a multi-part message in MIME format. --_----------=_1237214418850250 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain body --_----------=_1237214418850250 Content-Disposition: attachment; filename="signature.asc" Content-Transfer-Encoding: 7bit Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.11 (FreeBSD) iEYEABEKAAYFAkm+ZNIACgkQqrJJy0yxYQAu6ACfZLEAAiudAERIQ3seeuXBrhNq 0xUAniGRyHoxEonSGNjtDUJtdTs+1p0R =C1pk -----END PGP SIGNATURE----- --_----------=_1237214418850250--

In reply to creating PGP emails by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.