PowerShell(ファイルのハッシュ値)

PowerShellでファイルのハッシュ値を求めてみます。このようなファイルがあるとき、

PS C:\Users\takk\aaa> ls -name -re -i *.txt
12\74\06\63\23\file_1.txt
14\53\23\53\43\file_2.txt
14\92\16\14\68\file_3.txt
20\20\97\04\40\file_5.txt
57\93\43\76\7\file_6.txt
86\03\02\65\2\file_4.txt
PS C:\Users\takk\aaa>

Get-FileHashを使います。デフォルトではSHA256です。
各ファイルのSHA256の一覧を表示してみましょう。(lsはGet-ChildItemのエイリアス)

PS C:\Users\takk\aaa> ls -name -re -i *.txt | %{get-filehash $_}

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
SHA256          D0BD5F8C7875E14A074D98511EED9C3D3BF720F0BDFD008D16052563D4EA94B8       C:\Users\takk\aaa\12\74\06\63...
SHA256          3345CCC61C3BBED900FE98F6431B0E1CDF0BE5EDF627733294FF988F8C43022E       C:\Users\takk\aaa\14\53\23\53...
SHA256          67C5758FEF35C0F828B76D20F10858DB3C42259C9641C4DB89FC5B455584E932       C:\Users\takk\aaa\14\92\16\14...
SHA256          B1CC89066A64CEC02B2D0163C88B4613BB936F5B7DBEF54E1A596B56D3F43D30       C:\Users\takk\aaa\20\20\97\04...
SHA256          2363F9D309044538D5F6958A2D4F05A14E19A02A05E92E16165F2FAF721D5B1F       C:\Users\takk\aaa\57\93\43\76...
SHA256          008E87DE25C15AB9A45324626E2258AF65A499D99C6569002760C6B5185C87A7       C:\Users\takk\aaa\86\03\02\65...

別のアルゴリズムを指定するには、-Algorithmオプションを使います。(-Aは略)ファイルのMD5を求めてみます。

PS C:\Users\takk\aaa> ls -name -re -i *.txt | %{get-filehash -A MD5 $_}

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
MD5             218F5179EBAB0BB65A054150FDF65580                                       C:\Users\takk\aaa\12\74\06\63...
MD5             2D39D9EBC71AF0B26E22094BA9E115E0                                       C:\Users\takk\aaa\14\53\23\53...
MD5             EEE6D8EFB87B0791D94D2DD59312A5D9                                       C:\Users\takk\aaa\14\92\16\14...
MD5             616EBF0371CD7B162FD6BB7C941ED8A1                                       C:\Users\takk\aaa\20\20\97\04...
MD5             7317684E8336F2B29F414B5E9AC4FE31                                       C:\Users\takk\aaa\57\93\43\76...
MD5             CFFF13625862792EA22A94437D8C20A8                                       C:\Users\takk\aaa\86\03\02\65...


PS C:\Users\takk\aaa>

他にもSHA1、SHA384、SHA512、MACTripleDES、RIPEMD160が指定できます。

PS C:\Users\takk\aaa> ls -name -re -i *.txt | %{get-filehash -A SHA1 $_}

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
SHA1            D50AE4AFDEF5D8DDADE7ECE88184D07FA1ED96F2                               C:\Users\takk\aaa\12\74\06\63...
SHA1            7A1E424D949FD1FCED8582F7141F5A4926D06E5B                               C:\Users\takk\aaa\14\53\23\53...
SHA1            474C63E9FAB49BF8BCC9FCC947BC2B11B36EEBF6                               C:\Users\takk\aaa\14\92\16\14...
SHA1            FA8157FC68C63FB41B2465E011E01D9AD2AB5671                               C:\Users\takk\aaa\20\20\97\04...
SHA1            C2B24C5E23DC9B0C573F8E4E55780C8A9AE1B2E9                               C:\Users\takk\aaa\57\93\43\76...
SHA1            554B62A479ABE742C2E79CB3CCEC17F162BD6029                               C:\Users\takk\aaa\86\03\02\65...


PS C:\Users\takk\aaa> ls -name -re -i *.txt | %{get-filehash -A SHA384 $_}

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
SHA384          FDD204CCADA4615995B8C7CA39B10F5325D7FE18A4A85440373D7C2A83528C0C6A1... C:\Users\takk\aaa\12\74\06\63...
SHA384          FB2CE751A95120AC311C2C962240E804787E75831C4F5E1A3468FAA11BF69399A4B... C:\Users\takk\aaa\14\53\23\53...
SHA384          44875C31E0B8984CE357A0F8D8587DC3DFD5497FD96DF885A864AC645448D184473... C:\Users\takk\aaa\14\92\16\14...
SHA384          C2853017C46398CD63643C07FFC100790940996B05ED3E27F0F55E0197174F64EFC... C:\Users\takk\aaa\20\20\97\04...
SHA384          511B76D407CDC7D7291C332F0265CBE7528D4F0846072CE3D118A2B7302B0CFFFAE... C:\Users\takk\aaa\57\93\43\76...
SHA384          3EC69551AB36BD2C669DEA202E357F51E44A013EA881FC3D3A5F561583F60D19571... C:\Users\takk\aaa\86\03\02\65...


PS C:\Users\takk\aaa> ls -name -re -i *.txt | %{get-filehash -A SHA512 $_}

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
SHA512          A76783397DF47097AA4F26ED89F768476EA8BD40E8B1DFC01440BC5BC303738DAA3... C:\Users\takk\aaa\12\74\06\63...
SHA512          CCD17D9A7D5B6B305C73D034CD12C973696F173DEEA4E4F3D39859F30EB27912903... C:\Users\takk\aaa\14\53\23\53...
SHA512          A143A2FA355CE38E7D20C92A7E7B3F0121639539063E2328BF198F98534585F6E3D... C:\Users\takk\aaa\14\92\16\14...
SHA512          B0D0A0AD01CBF2AB99F678A61059F3ABEEE120B2E6F6B47F617F202A2EC6E151171... C:\Users\takk\aaa\20\20\97\04...
SHA512          FDAB0ED01617023A24B47958E143ECDE99845AEAEB92B463955CAEC896AA372BF77... C:\Users\takk\aaa\57\93\43\76...
SHA512          181D119A7924009FC102096E83FFD81C17E1A51CC981ADB4C7CE0D11EA244F98942... C:\Users\takk\aaa\86\03\02\65...


PS C:\Users\takk\aaa> ls -name -re -i *.txt | %{get-filehash -A MACTripleDES $_}

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
MACTRIPLEDES    FF8B3F61EA3009E6                                                       C:\Users\takk\aaa\12\74\06\63...
MACTRIPLEDES    25242A5795E6C6CF                                                       C:\Users\takk\aaa\14\53\23\53...
MACTRIPLEDES    A7065FAED6BCB0AC                                                       C:\Users\takk\aaa\14\92\16\14...
MACTRIPLEDES    A64D73AF42505439                                                       C:\Users\takk\aaa\20\20\97\04...
MACTRIPLEDES    E838F837F8CD47F0                                                       C:\Users\takk\aaa\57\93\43\76...
MACTRIPLEDES    A7E63E09109AF589                                                       C:\Users\takk\aaa\86\03\02\65...


PS C:\Users\takk\aaa> ls -name -re -i *.txt | %{get-filehash -A RIPEMD160 $_}

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
RIPEMD160       ECD4C2025F40781E1692221EF17F8B2C9C8BB19E                               C:\Users\takk\aaa\12\74\06\63...
RIPEMD160       36C0B12558F054486377E489ECC0373A8E239A8C                               C:\Users\takk\aaa\14\53\23\53...
RIPEMD160       F5C610EF7F1F1D31849EE4F00CA19E8D8E53D46B                               C:\Users\takk\aaa\14\92\16\14...
RIPEMD160       ECC87B539406FDE866CB47415B7096D85075C1D6                               C:\Users\takk\aaa\20\20\97\04...
RIPEMD160       C2A8BF874288DFD01275F70E5335B60EC5CB5FA6                               C:\Users\takk\aaa\57\93\43\76...
RIPEMD160       BD5D69D4BBF99F9A8B63B868A51C95BF76A01CE9                               C:\Users\takk\aaa\86\03\02\65...


PS C:\Users\takk\aaa>

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA