{"id":3476,"date":"2016-01-13T23:00:25","date_gmt":"2016-01-13T22:00:25","guid":{"rendered":"http:\/\/michlstechblog.info\/blog\/?p=3476"},"modified":"2021-12-14T10:51:15","modified_gmt":"2021-12-14T09:51:15","slug":"powershell-md5sum-and-sha256sum-functions","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/powershell-md5sum-and-sha256sum-functions\/","title":{"rendered":"Powershell: md5sum and sha256sum Functions"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_3476 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_3476')){$('.twoclick_social_bookmarks_post_3476').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Powershell%3A%20md5sum%20and%20sha256sum%20Functions\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Averifing%20of%20a%20file%20is%20often%20done%20by%20builting%20an%20MD5%20or%20an%20sha256%20hash%20over%20it.%0D%0A%0D%0APowershell%20has%20no%20%22builtin%22%20functions%20for%20this%20purposes.%0D%0A%0D%0ASo%20I%20wrote%20some%20%3A-%29%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\\\/powershell-md5sum-and-sha256sum-functions\\\/\",\"post_id\":3476,\"post_title_referrer_track\":\"Powershell%3A+md5sum+and+sha256sum+Functions\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>verifing of a file is often done by builting an MD5 or an sha256 hash over it.<\/p>\n<p>Powershell has no &#8220;builtin&#8221; functions for this purposes.<\/p>\n<p>So I wrote some \ud83d\ude42<br \/>\n<!--more--><\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nfunction MD5Sum(&#x5B;string]$sFile)\r\n{\r\n\t$oMD5=&#x5B;System.Security.Cryptography.MD5]::Create()\r\n\t$oStream=&#x5B;System.IO.File]::OpenRead($sFile)\r\n\t$sMD5=&#x5B;System.BitConverter]::ToString($oMD5.ComputeHash($oStream)).Replace(&quot;-&quot; ,&quot;&quot;).ToLower()\r\n\t$oStream.Close()\r\n\treturn($sMD5)\r\n}\r\n<\/pre>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nfunction sha256sum(&#x5B;string]$sFile)\r\n{\r\n\t$oSHA256=&#x5B;System.Security.Cryptography.SHA256]::Create()\r\n\t$oStream=&#x5B;System.IO.File]::OpenRead($sFile)\r\n\t$sSHA256=&#x5B;System.BitConverter]::ToString($oSHA256.ComputeHash($oStream)).Replace(&quot;-&quot;,&quot;&quot;).ToLower()\r\n\t$oStream.Close()\r\n\treturn($sSHA256)\r\n}\r\n<\/pre>\n<p>Usage<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS C:\\&gt; sha256sum D:\\temp\\vshadow.exe\r\n7699187b710263779b97ebe63925d77769f15236f0aa506373dd92772bbcf87b\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, verifing of a file is often done by builting an MD5 or an sha256 hash over it. Powershell has no &#8220;builtin&#8221; functions for this purposes. So I wrote some \ud83d\ude42<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[344,4],"tags":[802,133,803,20],"class_list":["post-3476","post","type-post","status-publish","format-standard","hentry","category-powershell-scripting","category-windowsscripts","tag-md5sum","tag-powershell","tag-sha256sum","tag-windows-2"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/3476","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=3476"}],"version-history":[{"count":5,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/3476\/revisions"}],"predecessor-version":[{"id":8288,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/3476\/revisions\/8288"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=3476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=3476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=3476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}