{"id":6609,"date":"2019-10-08T22:14:36","date_gmt":"2019-10-08T20:14:36","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=6609"},"modified":"2021-12-14T10:49:23","modified_gmt":"2021-12-14T09:49:23","slug":"openssl-symmetric-en-and-decryption-of-a-file","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/openssl-symmetric-en-and-decryption-of-a-file\/","title":{"rendered":"OpenSSL: Symmetric en- and decryption of a file"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_6609 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_6609')){$('.twoclick_social_bookmarks_post_6609').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"OpenSSL%3A%20Symmetric%20en-%20and%20decryption%20of%20a%20file\",\"the_excerpt\":\"%0D%0AHi%2C%0D%0A%0D%0Athis%20post%20describes%20the%20en-%20and%20decryption%20of%20a%20file%20with%20a%20symmetric%20encryption%20algorithm.%0D%0A%0D%0ASymmetric%20encryption%20means%20encryption%20and%20decryption%20is%20only%20possible%20with%20the%20same%20secret%2Fpassword.%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/openssl-symmetric-en-and-decryption-of-a-file\\\/\",\"post_id\":6609,\"post_title_referrer_track\":\"OpenSSL%3A+Symmetric+en-+and+decryption+of+a+file\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p><!-- https:\/\/codingbee.net\/centos\/openssl-demo-encrypting-decrypting-files-using-both-symmetric-and-asymmetric-encryption --><br \/>\nHi,<\/p>\n<p>this post describes the en- and decryption of a file with a symmetric encryption algorithm.<\/p>\n<p>Symmetric encryption means encryption and decryption is only possible with the same secret\/password.<br \/>\n<!--more--><br \/>\nAn example. Create a file and encrypt a file with a password as single secret. <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmichael@debdev ~ # echo &quot;My Secret Data&quot; &gt; file.txt\r\nmichael@debdev ~ # openssl aes-256-cbc -e -in file.txt -out encypted_file.txt\r\nenter aes-256-cbc encryption password:\r\n<\/pre>\n<p>Decrypt the file with the given password<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmichael@debdev ~ # openssl aes-256-cbc -d -in encypted_file.txt -out clear_text_file.txt\r\n<\/pre>\n<p>also possible:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmichael@debdev ~ # openssl enc -in file.txt -out encypted_file.txt -e -aes256\r\nenter aes-256-cbc decryption password:\r\nmichael@debdev ~ # openssl enc -in encypted_file.txt -out clear_text_file.txt -d -aes256\r\nenter aes-256-cbc decryption password:\r\n<\/pre>\n<p>Its also possible to use a secret stored in a file respectily a key.<br \/>\nCreate a secret<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmichael@debdev ~ # openssl rand 256 &gt; myEncryptionKeyFile.key\r\n<\/pre>\n<p>Encrypt the file with my key<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmichael@debdev ~ # openssl enc -in file.txt -out encypted_file.txt -e -aes256 -k myEncryptionKeyFile.key\r\n<\/pre>\n<p>Decrypt with the given key<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmichael@debdev ~ # openssl enc -in encypted_file.txt -out clear_text_file.txt -d -aes256 -k myEncryptionKeyFile.key\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, this post describes the en- and decryption of a file with a symmetric encryption algorithm. Symmetric encryption means encryption and decryption is only possible with the same secret\/password.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1036,466],"tags":[600,608,249,838,547,1126],"class_list":["post-6609","post","type-post","status-publish","format-standard","hentry","category-openssl","category-security","tag-decrypt","tag-encrypt","tag-file","tag-key","tag-openssl","tag-symmetric"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/6609","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=6609"}],"version-history":[{"count":12,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/6609\/revisions"}],"predecessor-version":[{"id":6622,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/6609\/revisions\/6622"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=6609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=6609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=6609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}