2012年2月7日火曜日

PowerShellでハッシュ計算

SHA256の場合

$sha = [Security.Cryptography.SHA256]::Create()
$file = [IO.File]::OpenRead("ファイルのパス")
$hash = $sha.ComputeHash($file)
$file.Dispose()
foreach ($b in $hash) { [Console].Write($b.ToString("X2")) }
[Console].WriteLine()
$sha.Dispose()

他のアルゴリズムの場合には「SHA256」の部分を「MD5」「SHA1」などに書き換えればよい.

0 件のコメント:

コメントを投稿