edgecase
Author: StJohn Piano
This page is subject to change at any time. It is not signed by its author or by Edgecase Datafeed.
413 words - 225 lines - 6 pages



Background:
- How to write an article
- GPG 1.4.10 Stateless Operations


Prerequisite:
- How to generate a GPG key




1) Place an article you have written into its own separate text file.

For this recipe, we'll assume that the file is named "article.txt".




2) Remove the last newline from the data in the article file.

Even if you didn't write one yourself, some text editors (e.g. vim) add one automatically.

Rationale: The article data should be completely enclosed in an "<article>" tag and an "</article>" end tag.




3) Create a temporary home directory for GPG to use.

mkdir tmp_home && chmod 700 tmp_home





4) Import the private key into the temporary directory.

gpg --no-default-keyring --homedir tmp_home --import <pathToPrivateKeyFile> > /dev/null 2>&1


Example:
gpg --no-default-keyring --homedir tmp_home --import ../keys/test_key_1_private_key.txt > /dev/null 2>&1





5) Sign the article file, producing a detached signature file.

The signature will be made using the imported private key.

gpg --no-default-keyring --homedir tmp_home --output detached_signature_file.txt.asc --armor --detach-sign article.txt





6) Delete the temporary directory.

rm -r tmp_home





7) Delete the GPG wrapper lines around the signature data.

Let's do a worked example.

Here is the content of an example signature file:

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQIcBAABAgAGBQJcqgvJAAoJEJeH0ledzFCiXIMP/ilrdyl9/JZEV6EA3i89FwQW
1jNwjJ1WCmrYt3ydMxhvXbM6Ygd0V0sUNWFW/74CrDsV4PeqVP11WNUtCSlQEJ1G
/R/JjFegHv5dc3dHbhOeHIUqqP9SQb/KyjL59Hp/cVBmvKCqVZrgg9q0/nmhC3rh
205CGZnbcT/HjQj9wFIQ/p26GoFLFIJ937hOU3z3OlgZA4LfN/WnXvbbNMVn1zry
vz40L4Mbqd4BbUqsjSscY3xPUPlP3RnvHu5juXUByzVxV4zy17b+a0PGpSckTMHO
yQbYS53mX8j8G68KxGmFuB8Uwq/5QxvvmuMBOHsvJnF71d1zMsHRrWcBaE24hDlY
qYTfwnjhXsK/N/xA4PrzwhGZy1i1rOq1PMAQHuTFuuUxJUsOJLp7/BC5fBT3HXoj
vynQv0pk/eThz16DZPPlQ4P/ypfAYuruxMLkgnGlUjnB2vc05kAgTYV2z/YgOMxM
ZVZgtRFIw1G2rqYzvx7uiseQFbl9osi+Iab9SMmixBVClMA+qYHPYzbxEy223N5d
OTIADtci0jcS2L0DzXdLFhiHtHtt9/SZSZsXw+R1y1vZv/QcCZYrSPuqbRn6vssT
VlW67Jqnx5Zx4Y9VpxKmPrX7rEVqOgNgPh0IfgzaKJstb7Kmr8Nz/RByeWxYRg9e
zvXZSkj35QaJWhATLiCY
=PRNX
-----END PGP SIGNATURE-----



Delete these lines at the top:

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)


And this one at the bottom:

-----END PGP SIGNATURE-----





8) Wrap the signature data in an "<author_signature>" tag.

Result:

<author_signature>
iQIcBAABAgAGBQJcqgvJAAoJEJeH0ledzFCiXIMP/ilrdyl9/JZEV6EA3i89FwQW
1jNwjJ1WCmrYt3ydMxhvXbM6Ygd0V0sUNWFW/74CrDsV4PeqVP11WNUtCSlQEJ1G
/R/JjFegHv5dc3dHbhOeHIUqqP9SQb/KyjL59Hp/cVBmvKCqVZrgg9q0/nmhC3rh
205CGZnbcT/HjQj9wFIQ/p26GoFLFIJ937hOU3z3OlgZA4LfN/WnXvbbNMVn1zry
vz40L4Mbqd4BbUqsjSscY3xPUPlP3RnvHu5juXUByzVxV4zy17b+a0PGpSckTMHO
yQbYS53mX8j8G68KxGmFuB8Uwq/5QxvvmuMBOHsvJnF71d1zMsHRrWcBaE24hDlY
qYTfwnjhXsK/N/xA4PrzwhGZy1i1rOq1PMAQHuTFuuUxJUsOJLp7/BC5fBT3HXoj
vynQv0pk/eThz16DZPPlQ4P/ypfAYuruxMLkgnGlUjnB2vc05kAgTYV2z/YgOMxM
ZVZgtRFIw1G2rqYzvx7uiseQFbl9osi+Iab9SMmixBVClMA+qYHPYzbxEy223N5d
OTIADtci0jcS2L0DzXdLFhiHtHtt9/SZSZsXw+R1y1vZv/QcCZYrSPuqbRn6vssT
VlW67Jqnx5Zx4Y9VpxKmPrX7rEVqOgNgPh0IfgzaKJstb7Kmr8Nz/RByeWxYRg9e
zvXZSkj35QaJWhATLiCY
=PRNX
</author_signature>





9) Place the signature data at the end of the article file, and wrap the result with a "<signed_article>" tag.

Here is the simplest possible article:

<article>
<title>Viewpoint</title>
<author_name>stjohn_piano</author_name>
<date>2017-06-28</date>
<signed_by_author>no</signed_by_author>
<content></content>
</article>


After we add the signature data and the "<signed_article>" tag, it will look like this:

<signed_article>
<article>
<title>Viewpoint</title>
<author_name>stjohn_piano</author_name>
<date>2017-06-28</date>
<signed_by_author>no</signed_by_author>
<content></content>
</article>
<author_signature>
iQIcBAABAgAGBQJcqgvJAAoJEJeH0ledzFCiXIMP/ilrdyl9/JZEV6EA3i89FwQW
1jNwjJ1WCmrYt3ydMxhvXbM6Ygd0V0sUNWFW/74CrDsV4PeqVP11WNUtCSlQEJ1G
/R/JjFegHv5dc3dHbhOeHIUqqP9SQb/KyjL59Hp/cVBmvKCqVZrgg9q0/nmhC3rh
205CGZnbcT/HjQj9wFIQ/p26GoFLFIJ937hOU3z3OlgZA4LfN/WnXvbbNMVn1zry
vz40L4Mbqd4BbUqsjSscY3xPUPlP3RnvHu5juXUByzVxV4zy17b+a0PGpSckTMHO
yQbYS53mX8j8G68KxGmFuB8Uwq/5QxvvmuMBOHsvJnF71d1zMsHRrWcBaE24hDlY
qYTfwnjhXsK/N/xA4PrzwhGZy1i1rOq1PMAQHuTFuuUxJUsOJLp7/BC5fBT3HXoj
vynQv0pk/eThz16DZPPlQ4P/ypfAYuruxMLkgnGlUjnB2vc05kAgTYV2z/YgOMxM
ZVZgtRFIw1G2rqYzvx7uiseQFbl9osi+Iab9SMmixBVClMA+qYHPYzbxEy223N5d
OTIADtci0jcS2L0DzXdLFhiHtHtt9/SZSZsXw+R1y1vZv/QcCZYrSPuqbRn6vssT
VlW67Jqnx5Zx4Y9VpxKmPrX7rEVqOgNgPh0IfgzaKJstb7Kmr8Nz/RByeWxYRg9e
zvXZSkj35QaJWhATLiCY
=PRNX
</author_signature>
</signed_article>





10) Result.

We have created a signature for the article, and added this signature to the data, producing a signed article file.

Note: A worked example with included output is available in the article GPG 1.4.10 Stateless Operations, in the section GPG 1.4.10 Stateless Operations With Example Output, in the part "7) Sign a file using a specific private key, producing a detached signature file".