FileHash
詳細
- FileHashが生成する値はファイルの生のバイト数に基づく.
- ファイルは,"file",File["file"],CloudObject["url"]あるいはInputStream[…]で指定できる.入力ストリームはBinaryFormatTrueで開かれたものでなければならない.
- FileHashは次の range 指定をサポートする.
-
n 最初の n バイト -n 最後の n バイト {n} n バイトのみ {m,n} m 番目から n 番目までのバイト 0 バイトなし All 全バイト - FileHash[{stream,range},…]は,事実上,それまでのストリーム位置を無視して,入力ストリーム中の指定された範囲のバイト位置のデータを抽出する.
- 各 filespec は file または{file,range}でよい.
- 可能なハッシュコードの型には次のようなものがある.
-
"Adler32" アドラー32ビット巡回冗長検査 "CRC32" 32ビット巡回冗長検査 "MD2" 128ビットMD2コード "MD4" 128ビットMD4コード "MD5" 128ビットMD5コード(デフォルト) "RIPEMD160" 160ビットRIPEMDコード "RIPEMD160SHA256" SHA256に従うRIPEMD-160(ビットコインで使われているような) "SHA" 160ビットSHA-1コード "SHA256" 256ビットSHAコード "SHA256SHA256" Double SHA-256コード(ビットコインで使われているような) "SHA384" 384ビットSHAコード "SHA512" 512ビットSHAコード "SHA3-224" 224ビットSHA3コード "SHA3-256" 256ビットSHA3コード "SHA3-384" 384ビットSHA3コード "SHA3-512" 512ビットSHA3コード "Keccak224" 224ビットKeccakコード "Keccak256" 256ビットKeccakコード "Keccak384" 384ビットKeccakコード "Keccak512" 512ビットKeccakコード - FileHashは,デフォルトで,128ビットのMD5コードを使う.
- 次は,使用可能な形式である.
-
"Integer" 整数(デフォルト) "DecimalString" 十進文字列 "HexString" 十六進文字列 "Base36String" 底36の英数文字列 "Base64Encoding" 底64符号化 "ByteArray" 明示的なバイト配列としてのハッシュコード - Wolfram言語の以前のバージョンとの互換性のために,FileHash[file,"type",range]とFileHash[file,"type",range,"format"]というシンタックスがサポートされている.
例題
すべて開く すべて閉じる例 (5)
FileHash[FindFile["ExampleData/ocelot.jpg"]]FileHash[FindFile["ExampleData/ocelot.jpg"], "SHA512"]ファイルの最初の100バイトの"SHA512"ハッシュコード:
FileHash[{FindFile["ExampleData/ocelot.jpg"], 100}, "SHA512"]FileHash[FindFile["ExampleData/ocelot.jpg"], "MD5", "HexString"]CloudObjectのハッシュ:
obj = CloudPut[123, "test"];FileHash[obj]FileHash[obj, "SHA256"]スコープ (11)
ファイルと範囲指定 (6)
ファイルの最初の100バイトについて,ハッシュ値を計算する:
glasses = FindFile["ExampleData/glasses.png"];FileHash[{File[glasses], 100}, "SHA"]FileHash[{File[glasses], {1, 100}}, "SHA"]FileHash[{File[glasses], -100}, "SHA"]FileHash[{File[glasses], {-100, -1}}, "SHA"]100バイト目から200バイト目までのハッシュ値を計算する:
FileHash[{File[glasses], {100, 200}}, "SHA"]最初と最後の各100バイトを除く全バイトについてのハッシュ値を計算する:
FileHash[{File[glasses], {101, -101}}, "SHA"]FileHash[{File[glasses], {100}}, "SHA"]FileHash[{File[glasses], 0}, "SHA"]FileHash[{FindFile["ExampleData/spikey2.png"], FindFile["ExampleData/ocelot.jpg"], FindFile["ExampleData/pearls.png"]}]完全なファイルのハッシュをそのいくつかの部分集合とともに求める:
pearls = FindFile["ExampleData/pearls.png"];FileHash[{pearls, {pearls, 100}, {pearls, {101, -101}} , {pearls, -100}}]CloudObjectを作る:
obj = CloudPut[46, "test"];CloudObjectに入っているデータのハッシュを求める:
FileHash[obj]FileHash[{obj, {1, -1}}, "MD5", "Integer"]ハッシュングのために,CloudObjectからのデータが改行を含む文字列として表される:
Hash[ToString[46] <> "
", "MD5"]Hash[StringToByteArray["46
"], "MD5"]strm = OpenRead["ExampleData/glasses.png", BinaryFormat -> True]FileHash[strm]SetStreamPosition[strm, 50]FileHash[strm]Close[strm]co = CloudObject[];
file = CreateFile[];Put[46!, file];
CloudPut[46!, co];strm = OpenRead[file, BinaryFormat -> True]FileHash[{File[file], co, strm}]Close[strm];ハッシュのタイプと形式 (5)
Grid[{#, FileHash[FindFile["ExampleData/pearls.png"], #]}& /@ {"Adler32", "CRC32", "MD2", "MD4", "MD5", "RIPEMD160", "RIPEMD160SHA256", "SHA", "SHA256", "SHA256SHA256", "SHA384", "SHA512"}, Alignment -> Left, Dividers -> All]FileHash[FindFile["ExampleData/ocelot.jpg"], "SHA512", "Integer"]IntegerQ[%]十進列として与えられた,先頭の0を含む512ビットSHAコード:
FileHash[FindFile["ExampleData/ocelot.jpg"], "SHA512", "DecimalString"]StringQ[%]Grid[{#, FileHash[FindFile["ExampleData/ocelot.jpg"], "SHA", #]}& /@ {"DecimalString", "HexString", "Base36String", "Base64Encoding"}, Alignment -> Left]ByteArrayとして与えられた,ファイルの最初の50バイトのDouble SHAコード:
ba = FileHash[{FindFile["ExampleData/financialtimeseries.csv"], 50}, "SHA256SHA256", "ByteArray"]256 == Length[ba] * 8ba//Normal特性と関係 (10)
FileHash[FindFile["ExampleData/atoms.wxf"]] == FileHash[FindFile["ExampleData/atoms.wxf"], "MD5"]デフォルトの範囲指定はAllである:
FileHash[FindFile["ExampleData/atoms.wxf"], "MD5"] == FileHash[{FindFile["ExampleData/atoms.wxf"], All}, "MD5"]FileHash[FindFile["ExampleData/atoms.wxf"], "MD5"] == FileHash[{FindFile["ExampleData/atoms.wxf"], {1, -1}}, "MD5"]0バイトのハッシュコードを求めることは,空ファイルのハッシュコードを求めることと同じである:
file = CreateFile[];FileHash[{FindFile["ExampleData/atoms.wxf"], 0}, "MD5"] == FileHash[{file, 0}, "MD5"]DeleteFile[file]FileHash[FindFile["ExampleData/atoms.wxf"], "MD5"] == FileHash[FindFile["ExampleData/atoms.wxf"], "MD5", "Integer"]"DecimalString"は,必要な場合は0で充填された,"Integer"の文字列バージョンである:
{FileHash[{FindFile["ExampleData/atoms.wxf"], 1}, "Adler32"], FileHash[{FindFile["ExampleData/atoms.wxf"], 1}, "Adler32", "DecimalString"]}"HexString"は,必要な場合は0で充填された,底16の表現である:
{FileHash[{FindFile["ExampleData/atoms.wxf"], 1}, "Adler32"], FileHash[{FindFile["ExampleData/atoms.wxf"], 1}, "Adler32", "HexString"]}"Base36String"は,要な場合は0で充填された,底36の表現である:
{FileHash[{FindFile["ExampleData/atoms.wxf"], 1}, "Adler32"], FileHash[{FindFile["ExampleData/atoms.wxf"], 1}, "Adler32", "Base36String"]}"Base64Encoding"は,底64の符号化を使って結果のバイトを符号化する:
FileHash[{FindFile["ExampleData/atoms.wxf"], 1}, "Adler32", "Base64Encoding"]% === BaseEncode[FileHash[{FindFile["ExampleData/atoms.wxf"], 1}, "Adler32", "ByteArray"]]FileHash[file,code]は,事実上,Hash[ReadByteArray[file],code]と同じである:
FileHash[FindFile["ExampleData/ocelot.jpg"], "MD5"] === Hash[ReadByteArray[FindFile["ExampleData/ocelot.jpg"]], "MD5"]FileHash[file,code]は,事実上,Hash[ByteArray@Import[file,"Byte"]]と同じである:
FileHash[FindFile["ExampleData/ocelot.jpg"], "SHA"] == Hash[ByteArray@Import["ExampleData/ocelot.jpg", "Byte"], "SHA"]テキスト
Wolfram Research (2007), FileHash, Wolfram言語関数, https://reference.wolfram.com/language/ref/FileHash.html (2020年に更新).
CMS
Wolfram Language. 2007. "FileHash." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/FileHash.html.
APA
Wolfram Language. (2007). FileHash. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FileHash.html
BibTeX
@misc{reference.wolfram_2026_filehash, author="Wolfram Research", title="{FileHash}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/FileHash.html}", note=[Accessed: 22-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_filehash, organization={Wolfram Research}, title={FileHash}, year={2020}, url={https://reference.wolfram.com/language/ref/FileHash.html}, note=[Accessed: 22-November-2026]}