PowerShell hashing

Windows specific questions.
Post Reply
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

PowerShell hashing

Post by deltarho[1859] »

I did not know this. <smile>

If you have Windows PowerShell, open it.

1) Type 'Get-FileHash'.
2) Follow that with a Drag & Drop of a file to hash.
3) Follow that with '-Algorithm <whatever>' where <whatever> is MD5, SHA1 or SHA256.
4) Press Enter.

We now get the hash.

We can use SHA512 but on my machine, it runs out of space and clips the result.

Of course, I may be the only one who did not know this but I doubt that.

Where did I learn about it? I am on 'How-To Geek' mailing list. I have seen a few 'Didn't know that' topics of late.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: PowerShell hashing

Post by dodicat »

Nice.

Code: Select all

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
SHA256          582432F3A286ADA8240B859DFC2707B09C4D90E2387335D86E8CE824D81EF4D4       C:\Users\User\Desktop\fb-manu...


PS C:\Users\User\Desktop>  
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: PowerShell hashing

Post by badidea »

For those on linux, similar tools via the terminal: md5sum, sha1sum, sha224sum, sha256sum, sha384sum, sha512sum or via shasum with additional parameters. E.g.:

Code: Select all

sha256sum test_time.cir 
9f1582e9bf5e6b03ed71a828c1a49d5556ec41f58bc7789b452908247305a4a3  test_time.cir
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: PowerShell hashing

Post by deltarho[1859] »

Well done Linux!
macko17
Posts: 8
Joined: Jun 04, 2017 0:22

Re: PowerShell hashing

Post by macko17 »

This has been in Windows for a while, the powershell thing is (probably) just a wrapper around it.

certutil -hashfile fileName HashType

Hashtype is MD2, MD4, MD5, SHA1, SHA256, SHA384, SHA512
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: PowerShell hashing

Post by deltarho[1859] »

@macko17

Thanks for that - we live and learn.

The nice thing about certutil is that there is no clipping on SHA512.
St_W
Posts: 1626
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: PowerShell hashing

Post by St_W »

deltarho[1859] wrote:We can use SHA512 but on my machine, it runs out of space and clips the result.
Are you referring to the output format? You can easily change that, e.g. like this:

Code: Select all

PS D:\dev\fbc> Get-FileHash readme.txt -Algorithm SHA512 | Format-List

Algorithm : SHA512
Hash      : D3B48B6756D35DB2A9E91CA135FDEE303F2DAF7FF139EC46D3512A2329E080D45D4149EA15013B0B8ED8E01CA14332D7E4AA5C578C0
            F6FEEF26AA04DDE9B3428
Path      : D:\dev\fbc\readme.txt


PS D:\dev\fbc> (Get-FileHash readme.txt -Algorithm SHA512).Hash
D3B48B6756D35DB2A9E91CA135FDEE303F2DAF7FF139EC46D3512A2329E080D45D4149EA15013B0B8ED8E01CA14332D7E4AA5C578C0F6FEEF26AA04DDE9B3428
PS D:\dev\fbc>
Instead of "Format-List" you can also use its short alias "fl".
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: PowerShell hashing

Post by deltarho[1859] »

@St_W Thank you.

This thread is turning into a KB. <smile> I must get a PowerShell tutorial for my Kindle Paperwhite - there are a few to choose from.
PaulSquires
Posts: 1002
Joined: Jul 14, 2005 23:41

Re: PowerShell hashing

Post by PaulSquires »

Google just release "Tink", a simple, cross-platform cryptography library:
https://github.com/google/tink

You might be interested in that?
I haven't investigated to see if it can be easily called from a FB program.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: PowerShell hashing

Post by jj2007 »

It can be done programmatically, too. Source:

Code: Select all

  If_ GetHash(FileRead$(<CL$()>), LastFileSize, md5) Then Inkey "The MD5 of ", CL$(), " is ", Hex$(xmm0)
Output with fbc.exe (31.1.16, 1979904 bytes) dragged over the exe:

Code: Select all

The MD5 of C:\AllBasics\FreeBasic\Fb64\bin\fbc.exe is 7101A636 562F2F90 C8C698A7 3282A9A6
Under the hood are the Crypt*Hash API functions.
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: PowerShell hashing

Post by deltarho[1859] »

PaulSquires wrote:I haven't investigated to see if it can be easily called from a FB program.
with the release of version 1.2.0. This is a milestone for the project, as it’s the first version to have well-tested support for Android, iOS, and C++. (Go and JavaScript support are currently in-development.)
I cannot speak for others but I have been 'doing' crypto for over 13 years and have been adding to my own 'library' over the years. I first used ECDSA with my Encrypternet so now have code for that. I already had code for AES-CBC, RSA, and SHA256 used in Encrypternet, which comes in at only just over 150KB. I have looked at many crypto libraries but never took to any of them - I'd much rather code lower down with the Windows APIs. An analogy would be the SDK programmers at PowerBASIC not taking to DDT.
Post Reply