{"id":1321,"date":"2023-03-17T18:36:18","date_gmt":"2023-03-17T18:36:18","guid":{"rendered":"https:\/\/jackofalltradesmasterofsome.com\/blog\/?p=1321"},"modified":"2023-03-17T18:36:38","modified_gmt":"2023-03-17T18:36:38","slug":"decrypt-and-save-a-text-or-cvs-with-pgpy-and-python","status":"publish","type":"post","link":"https:\/\/jackofalltradesmasterofsome.com\/blog\/2023\/03\/17\/decrypt-and-save-a-text-or-cvs-with-pgpy-and-python\/","title":{"rendered":"Decrypt and Save a Text or CVS with PGPY and Python"},"content":{"rendered":"\n<p>Hopefully this helps someone to Decrypt and Save a Text or CVS file with PGPY and Python. Use Kleopatra and \u00a0OpenPGP to generate and save your key. You can obtain it by Exporting &#8220;Backup Secret Keys&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"289\" height=\"363\" src=\"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2023\/03\/image.png\" alt=\"\" class=\"wp-image-1322\" srcset=\"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2023\/03\/image.png 289w, https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2023\/03\/image-239x300.png 239w\" sizes=\"auto, (max-width: 289px) 100vw, 289px\" \/><\/figure>\n\n\n\n<p>Then run this code to decrypt and save the file in whatever location you need.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pgpy\r\n\r\nemsg = pgpy.PGPMessage.from_file('YOUR FILE.pgp')\r\nkey,_  = pgpy.PGPKey.from_file('YOUR PRIVATE KEY.asc')\r\nwith key.unlock('YOUR PGP PASSWORD'):\r\n    print (key.decrypt(emsg).message)\r\n    with open(\"my_file.txt\", \"wb\") as binary_file:\r\n   \r\n        # Write bytes to file\r\n        binary_file.write(key.decrypt(emsg).message)<\/code><\/pre>\n\n\n\n<p>That&#8217;s it! Keeping it short and simple.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hopefully this helps someone to Decrypt and Save a Text or CVS file with PGPY and Python. Use Kleopatra and \u00a0OpenPGP to generate and save your key. You can obtain it by Exporting &#8220;Backup Secret Keys&#8221;. Then run this code to decrypt and save the file in whatever location you need. That&#8217;s it! Keeping it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1321","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/posts\/1321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/comments?post=1321"}],"version-history":[{"count":1,"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/posts\/1321\/revisions"}],"predecessor-version":[{"id":1323,"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/posts\/1321\/revisions\/1323"}],"wp:attachment":[{"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/media?parent=1321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/categories?post=1321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/tags?post=1321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}