LoginSignup
4
1

More than 5 years have passed since last update.

Windows でファイルの MD5 や SHA1 ハッシュ値を求める

Posted at

Qiita 投稿したことなくて試してみたくなったので、数年前の自分のブログからの転載

Linux ならコマンド一発で求められるハッシュ値も、Windows でできないかなと思って試した時のメモです。

ハッシュ値の求め方

みんな大好きワンライナーです
当時手元に Windows Vista しかなかったので、PowerShell 2.0 で動くようにしています

# MD5
[System.Security.Cryptography.MD5]::Create().ComputeHash((New-Object IO.StreamReader "ファイルパス").BaseStream) | % { write-host $_.Tostring("x2") -noNewLine }

# SHA1
[System.Security.Cryptography.SHA1]::Create().ComputeHash((New-Object IO.StreamReader "ファイルパス").BaseStream) | % { write-host $_.Tostring("x2") -noNewLine }

これが PowerShell 4.0 からは Get-FileHash で一発とか熱いですね

PowerShell コマンドを右クリックメニューに入れる

Windows だと、コマンドラインでは使いにくいですよね
そこで右クリックメニューに入れます

  1. regedit を起動する
  2. [HKEY_CLASSES_ROOT]-[*]-[shell] を右クリックして [新規]-[キー]を選択
  3. キーに任意の名前をつける(右クリックした時のメニュー名になる)
  4. 3 で作ったキーを右クリックして [新規]-[キー]を選択、名前を commandにする
  5. 4 で作ったキー command をクリックして、右のウィンドウにある (規定)をダブルクリックする値のデータにコードを入れる
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoExit -command "[System.Security.Cryptography.MD5]::Create().ComputeHash((New-Object IO.StreamReader '%1').BaseStream) | %% { write-host $_.Tostring('x2') -noNewLine }; write-host ''"

regedit.png

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1