ãã¡ã¤ã«ã®å¤æ´ãæ¤ç¥ããæã«ä¸è¬çã«è¡ãããã®ã ããã·ã¥å¤ã®æ¯è¼ã§ãããã¡ã¤ã«ã®å¤æ´æ¤ç¥ã¯ããªãã¡æ¹ããããªããããã¡ã¤ã«ãæ´æ°ããã¦ãªãããªã©ãããã¾ãã§ã¯ãªãå¤åã®æ¤ç¥ãæå³ããã®ã§ããããã®ã£ã¦å¤§äºã§ãã*1
æ¥ä»ããã¡ã¤ã«åã§ã®å¤æãã¡ã絶対ã
ä¾ãã°ãMySQL ãªã©ããã¦ã³ãã¼ããããã¨ããã¨ããã¦ã³ãã¼ããªã³ã¯ãã°ã« ããã·ã¥å¤ãããã¾ãããï¼ãã¦ã³ãã¼ãããããã®ããã®å¤ã¨ä¸è´ãã¦ããªãå ´åã¯æ¹ããããã£ããã¨ãæ°ã¥ããããã§ãã
ä»åã¯ãPowerShell v3 *2ãããã㯠v4 ã§æ¨æºã®Cmdletãã便å©ã«ãã¡ã¤ã«ããã·ã¥ãåå¾ããããã®é¢æ°ã®ç´¹ä»ã§ãã
Linux ã§ã®ããã·ã¥å¤ç¢ºèª
Linux ã§ã¯ãopenssl ã®openssl sha1
ã§ãã£ãããmd5sum
ã sha1sum
ãshasum
ãsha224sum
ãsha256sum
ãsha384sum
ãsha512sum
ã¨ã¾ãã¯ãããµã¤ã¼ã«ä¸è¬çãªæ¨æºç°å¢ã§ããã«ç¢ºèªã§ãã¾ãã
便å©ãç°¡åã
Windows ã§ã®ããã·ã¥å¤ç¢ºèª
ç¿»ã£ã¦ Windows ã§ã¯ã¨ããã¨ãWindows 8.1 / 2012 R2 ã§æ¨æºã¨ãªã£ã PowerShell v4 ã¾ã§ã¯æ¨æºã§ãã¡ã¤ã«ããã·ã¥ã確èªããã¦ã¼ãã£ãªãã£ã¯æä¾ããã¦ãã¾ããã§ãããPowerShell v3ã§ã¯æ¨æºã§Cmdletããªããã§ããã
å®éã«ã¯ã.NET ããå©ãã°ç°¡åã§ãããã³ãã³ãã©ã¤ã³ã§ããã£ã¨ä½¿ãããã¨ããæã«ã以å㯠cmd ã PowerShell ã§ãµãã¼ãããã¦ãããæ²ããæãããããã¨ãå¤ãã£ãã§ãã
cmd ã§ã®ç¢ºèª
File Checksum Integrity Verifier (FCIV) ã使ã人ãå¤ãããã§ããã
ä»ä½¿ã人ããããã¯ç¥ãã¾ãããç§ã使ã£ããã¨ããã¾ãã()
PowerShell v4 ããæ¨æºCmdletã®æä¾
ãã¦PowerShell v4 ã«ã¯ãGet-FileHash
ã¨ãã Cmdlet ã追å ããã¦ãã¾ãã
ããã使ããã¨ã§ããã¡ã¤ã«ã®ããã·ã¥å¤ãmd5 ã sha1ãsha256 ãªã©ãå種ã¢ã«ã´ãªãºã ã§ç®åºã§ãã便å©ããã§ãã
ä½ãã以ä¸ã®ããã« Path ã« [String[]] ã渡ããªãã¨èªèº«ã§ã¯ å帰ç(Recursive)ã«ãã¡ã¤ã«ãæ¤ç¥ãã¦ãããªãã®ã§ããã©ãããã§ãã*3
ã¤ã¾ããã¤ãã©ã¤ã³ã§æ¸¡ããã
Get-ChildItem -Recurse -File | Get-FileHash
å¤æ°ããã©ã¡ã¼ã¿ã§æ¸¡ããã§ãã
$file = Get-ChildItem -Recurse -File Get-FileHash -Path $file.FullName
åå¾çµæã¯ãå©ç¨ãããã¢ã«ã´ãªãºã ã¨ããã·ã¥å¤ããã¹ãããããã£ã«æã£ã¦ããã®ã§æä½ã容æã§ããã
Algorithm Hash Path --------- ---- ---- SHA256 7D5D4F18A97D8E4A16EC6432094F708C7CA558349D6D2C78DBB19FB771354289 D:\GitHub\Pow... SHA256 875CF5087260F2A5CB4F37632A34F6730D0F81D3A4E68B3663A1B72B08A20735 D:\GitHub\Pow... SHA256 F78E66EEA3E67912EB2F2ED7BAE499BEEEE86F1C3001B0BDCE6B4217059ECC12 D:\GitHub\Pow... SHA256 FE37E4F26DFAFFF8146AEF8516B91083DE8A904A14AA7DA33710CC8778BAEDEB D:\GitHub\Pow... SHA256 F4A0896AAF8E71A539503EE0EB27BD8CC0B0ABE449A12A55F61A6F5030B21BCF D:\GitHub\Pow...
ãªã¹ã表示ããã¨ããã§ããã
Algorithm : SHA256 Hash : 7D5D4F18A97D8E4A16EC6432094F708C7CA558349D6D2C78DBB19FB771354289 Path : D:\GitHub\PowerShellUtil\.gitattributes
PowerShell v3 ã§ãã¡ã¤ã«ã®ããã·ã¥å¤ã確èªããã
ã¯ãã.NET ã使ã£ã¦ãã ããããåç´ã« C# ã§æ¸ãã®ãPowerShell ã«ç§»æ¤ããã° okã§ãã
ããæ¨ã¦ã ã¨ãããªæãã§ããããã
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Security.Cryptography; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { if (args.Length == null) throw new ArgumentNullException(); var file = args[0]; var hash = GetFileHash(file); Console.WriteLine(hash); Console.ReadLine(); } static string GetFileHash(string file) { using (FileStream stream = File.OpenRead(file)) { SHA256Managed sha = new SHA256Managed(); byte[] hash = sha.ComputeHash(stream); return BitConverter.ToString(hash).Replace("-", String.Empty); } } } }
ã§ã¾ãããã
cmd > ConsoleApplication4.exe d:\GitHub\PowerShellUtil\Get-FileHashIndex\Get-FileHashIndex.ps1 00AF5018AEFF8B5C3F17E0B1ADF111E29F9AFB874C583B5740A605EEEF70744F
Cmdlet ã§ãããã®ã§ãããPowerShell Scriptã§ãåæ§ã«æ¸ãã¾ãã
åããã¦ãv4æ¨æºã® Get-FileHash
ã¨åæ§ã«å種ã¢ã«ã´ãªãºã ã®ãµãã¼ãããã¤ãã©ã¤ã³å
¥åãå¦çã®æé©åã-Recurse
ã®ãµãã¼ãããã¦ã¿ã¾ããã
GitHub ã§å ¬éãã¦ããã¾ãã
using ã使ãã Dispose æ¸ãã¦ãã*4ãè¥å¹² C# ã¨æ¸ãæ¹ãéãã¾ãããã£ã¦ããã¨ã¯ä¸ç·ã§ãã
v4ã® Get-FileHash
ã«æ¯ã¹ã¦ãåã v5 September Preview ç°å¢ã§ãåç¨åº¦é«éåãã¦ãã¾ãã*5
使ãæ¹ããåºåãå¤ãããªãã®ã§ä¾¿å©ã«ä½¿ã£ã¦ããã¦ãã ããã
Get-FileHashIndex -Path d:\GitHub\PowerShellUtil\Get-FileHashIndex\Get-FileHashIndex.ps1
Algorythm Hash Path --------- ---- ---- SHA256 00AF5018AEFF8B5C3F17E0B1ADF111E... D:\GitHub\PowerShellUtil\Get-F...
ã¾ã¨ã
ããã§ãv3 ã§ã ãã¡ã¤ã«ã®ããã·ã¥å¤ç¢ºèªã§ãã¾ããã¼ããã¼ãã
ãã©ã¡ã¼ã¿å ¥åã¨ãã¤ãã©ã¤ã³å ¥å両æ¹ããµãã¼ãããæ¸ãæ¹ã®åèã«ãªãã°å¹¸ãã§ãã
*1:FileStream ãªã®ããã¡ã¤ã«å ¨ä½ã Byteé åã§èªããã§ãå¤ããã¾ãã
*2:v2 㯠PSCustomObject ãªããã Add-Member ã«ç½®ãæ¿ããã°ãããããª
*3:LiteralPath ã§ãããã§ããç°¡ç¥ã§
*4:ãã¬ã¬
*5:ãã¤ãã©ã¤ã³ã®ã³ã¹ã? ãªããä½è¨ãªãã¨ãããããã¦ãã«ãã