0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【PowerShell】ダウンロードファイルの破損、改ざんがないか検証する

Posted at

①ダウンロードサイトから対象ファイルのチェックサムを取得する。
※CentOSの場合は、以下のページ。
対象ファイルのchecksumsのSHA256を取得する。
https://wiki.centos.org/Download

②ダウンロードしたファイルから作成したチェックサムを作成する。
7-Zipをインストールしている場合、
対象ファイルで右クリック「CRC SHA」>「SHA-256」で作成できる。

また、powershellコマンドでも取得できる。
・コマンド

Get-FileHash -Algorithm SHA256 C:\CentOS-7-x86_64-DVD-1810.iso

・実行結果

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
SHA256          6D44331CC4F6C506C7BBE9FEB8468FAD6C51A88CA1393CA6B8B486EA04BEC3C1       C:\CentOS-7-x86_64-DVD-1810.iso

③文字列を比較し、一致しているか(大文字・小文字の区別はしない)、確認する。
・比較検証を実施。例として、以下のpowershellコマンドを実行。

# ダウンロードサイトから取得したチェックサム(SHA256)
$a = "6d44331cc4f6c506c7bbe9feb8468fad6c51a88ca1393ca6b8b486ea04bec3c1"
# ローカルファイルから作成したチェックサム(SHA256)
$b = "6D44331CC4F6C506C7BBE9FEB8468FAD6C51A88CA1393CA6B8B486EA04BEC3C1"

# 比較処理(大文字・小文字を区別しない)
if($a -ieq $b){
  Write-Output '正常'
}else{
  Write-Output '異常'
}

・実行結果

正常
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?