{"id":271,"date":"2020-11-20T17:34:33","date_gmt":"2020-11-20T17:34:33","guid":{"rendered":"https:\/\/maboc.nl\/?p=271"},"modified":"2020-11-20T17:34:33","modified_gmt":"2020-11-20T17:34:33","slug":"gpg-encrypting-decrypting","status":"publish","type":"post","link":"https:\/\/maboc.nl\/?p=271","title":{"rendered":"GPG : Encrypting \/ Decrypting"},"content":{"rendered":"<p><a href=\"https:\/\/maboc.nl\/?p=181\" target=\"_blank\" rel=\"noopener noreferrer\">GPG index<\/a><\/p>\n<p>Finaly &#8230;we can start using gpg to encrypt the very secret stuff we need to keep secret for the public eye.<\/p>\n<p>Bob has very secret information in a file which he wants to send to Alice. Since the wellbeing of the nation depends on this, he wants to make sure that only Alice can read this information.<\/p>\n<p>Let&#8217;s see what he can do. First&#8230;what is this very secret message:<\/p>\n<pre style=\"font-family=courier; font-size=smaller;\">\r\n[bob@radijs ~]$ ls -l secret_stuff.txt \r\n-rw-rw-r--. 1 bob bob 18 20 nov 17:01 secret_stuff.txt\r\n<\/pre>\n<p>OK&#8230;.what&#8217;s in it:<\/p>\n<pre style=\"font-family=courier; font-size=smaller;\">\r\n[bob@radijs ~]$ cat secret_stuff.txt \r\nVery secret stuff\r\n<\/pre>\n<p>Well let&#8217;s encrypt it. Only alice@maboc.nl must be able to decrypt this file (-r recipient).<\/p>\n<pre style=\"font-family=courier; font-size=smaller;\">\r\n[bob@radijs ~]$ gpg --encrypt -r alice@maboc.nl secret_stuff.txt \r\n<\/pre>\n<p>This will give a binary encrypted file which may not be allowed by some preocessing (thin email). So we can also create a version which is ascii readable:<\/p>\n<pre style=\"font-family=courier; font-size=smaller;\">\r\n[bob@radijs ~]$ gpg --encrypt -r alice@maboc.nl --armor secret_stuff.txt\r\n<\/pre>\n<p>Let&#8217;s have a look at the files which we now have<\/p>\n<pre style=\"font-family=courier; font-size=smaller;\">\r\n[bob@radijs ~]$ ls -l secret_stuff.txt*\r\n-rw-rw-r--. 1 bob bob  18 20 nov 17:01 secret_stuff.txt\r\n-rw-rw-r--. 1 bob bob 549 20 nov 18:04 secret_stuff.txt.asc\r\n-rw-rw-r--. 1 bob bob 359 20 nov 18:03 secret_stuff.txt.gpg\r\n[bob@radijs ~]$\r\n<\/pre>\n<p>The binary file we are not going to look in (it will mess up my terminal), the ascii armored file looks like:<\/p>\n<pre style=\"font-family=courier; font-size=smaller;\">\r\n[bob@radijs ~]$ cat secret_stuff.txt.asc \r\n-----BEGIN PGP MESSAGE-----\r\n\r\nhQEMA0t1KIcPP+tcAQgAkVtaxl3jXQAM\/o307uXcVLuRYyXJzSJaCxIvCRHa0Lki\r\nb0m8C25Ps\/HGrodog\/B4Gcor7P29Mg26fuDhLsYGpivjgZ5aDGXnAOi7NQDfkUBz\r\nfo9A7fwWEiFmxp7kilESDRCX+43+kDMaEmHSedi0Xj44\/o9Upt\/c5IFl+OX7VDpI\r\nnYItoWpvGrfCHx1h5bDhN6sN\/UxzVei4tBekgaSX2KqBZAJm+9nhSaJ3w6\/\/dL3x\r\nA9OvhDSxhb21DTOtOyDqHF+v2ORRlIA0eT9kXg9bO6JWYk\/qe4bS0z3y9eLx+pdW\r\nUMnwxewz4CkMiDHpirIA4h3E8Ye+XR1cN47uwEQpjdJWAUG2LeD96qH4oxPjBUR0\r\ns3wOjCsilV5KwrVGJNUK1KWjq1u7iPqpOvXcqfQgCe50d0tCsSSoqqfuP9V8CbIa\r\nQYXPeoxFZpdYtGxu3h2\/\/kLWbmbMykA=\r\n=GVZV\r\n-----END PGP MESSAGE-----\r\n[bob@radijs ~]$\r\n<\/pre>\n<p>So &#8230; the encrypting is done.<\/p>\n<p>Bob, for instance, mails this encrypted file to Alice. As she get&#8217;s it she needs to decrypt it..let&#8217;s have a look:<\/p>\n<pre style=\"font-family=courier; font-size=smaller;\">\r\n[alice@radijs ~]$ ls -l secret_stuff.txt.*\r\n-rwxrwxr-x. 1 alice alice 549 20 nov 18:19 secret_stuff.txt.asc\r\n-rwxrwxr-x. 1 alice alice 359 20 nov 18:19 secret_stuff.txt.gpg\r\n<\/pre>\n<p>Let&#8217;s decrypt the ascii armored file:<\/p>\n<pre style=\"font-family=courier; font-size=smaller;\">\r\n[alice@radijs ~]$ gpg --decrypt secret_stuff.txt.asc \r\ngpg: encrypted with 2048-bit RSA key, ID 4B7528870F3FEB5C, created 2020-11-12\r\n      \"Alice <alice@maboc.nl>\"\r\n                                <=== gpg here asks for the password of Alice \r\n                                <=== at my system that's in a separate curses-window\r\n                                <=== That window is not shown here\r\nVery secret stuff\r\n[alice@radijs ~]$ \r\n<\/pre>\n<p>As you can see, gpg writes the output the STDOUT.<\/p>\n<p>Now decrypt the \"regular\" file:<\/p>\n<pre style=\"font-family=courier; font-size=smaller;\">\r\n[alice@radijs ~]$ gpg --decrypt secret_stuff.txt.gpg \r\ngpg: encrypted with 2048-bit RSA key, ID 4B7528870F3FEB5C, created 2020-11-12\r\n      \"Alice <alice@maboc.nl>\"\r\n                                <=== gpg here asks for the password of Alice \r\n                                <=== at my system that's in a separate curses-window\r\n                                <=== That window is not shown here\r\nVery secret stuff\r\n[alice@radijs ~]$ \r\n<\/pre>\n<p>Again, the output is on the STDOUT.<\/p>\n<p>For a small text file that may not be a problem. For a picture or so, this might produce a lot of garbage, let's redirect to a file:<\/p>\n<pre style=\"font-family=courier; font-size=smaller;\">\r\n[alice@radijs ~]$ gpg --decrypt secret_stuff.txt.gpg > secret_bob.txt\r\ngpg: encrypted with 2048-bit RSA key, ID 4B7528870F3FEB5C, created 2020-11-12\r\n      \"Alice <alice@maboc.nl>\"\r\n                                <=== gpg here asks for the password of Alice \r\n                                <=== at my system that's in a separate curses-window\r\n                                <=== That window is not shown here\r\n<\/pre>\n<p>And what is actually in that file:<\/p>\n<pre style=\"font-family=courier; font-size=smaller;\">\r\n[alice@radijs ~]$ cat secret_bob.txt \r\nVery secret stuff\r\n[alice@radijs ~]$\r\n<\/pre>\n<p>Allright...that's all there is to it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GPG index Finaly &#8230;we can start using gpg to encrypt the very secret stuff we need to keep secret for the public eye. Bob has very secret information in a file which he wants to send to Alice. Since the wellbeing of the nation depends on this, he wants to make sure that only Alice [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[45,46,37,44],"class_list":["post-271","post","type-post","status-publish","format-standard","hentry","category-privacy","tag-decrypt","tag-encrypt","tag-gpg","tag-pr"],"_links":{"self":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts\/271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=271"}],"version-history":[{"count":5,"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts\/271\/revisions"}],"predecessor-version":[{"id":276,"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts\/271\/revisions\/276"}],"wp:attachment":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}