FileHash

FileHash["file"]

gives an integer hash code for the contents of the specified file.

FileHash["file","type"]

gives an integer hash of the specified type.

FileHash["file","type",range]

gives an integer hash code for the specified range of bytes.

FileHash["file","type",range,"format"]

gives a hash code in the specified format.

Details

  • Values generated by FileHash are based on the raw bytes in a file.
  • Possible hash code types include:
  • "Adler32"Adler 32-bit cyclic redundancy check
    "CRC32"32-bit cyclic redundancy check
    "MD2"128-bit MD2 code
    "MD4"128-bit MD4 code
    "MD5"128-bit MD5 code (default)
    "RIPEMD160"160-bit RIPEMD code
    "RIPEMD160SHA256"RIPEMD-160 following SHA-256 (as used in Bitcoin)
    "SHA"160-bit SHA-1 code
    "SHA256"256-bit SHA code
    "SHA256SHA256"double SHA-256 code (as used in Bitcoin)
    "SHA384"384-bit SHA code
    "SHA512"512-bit SHA code
  • FileHash by default uses 128-bit MD5 code.
  • FileHash supports the following range specifications:
  • nfirst n bytes
    -nlast n bytes
    {m,n}bytes m through n
    0no bytes
    Allall bytes
  • Range specification All is equivalent to {1,-1}.
  • FileHash works on files and streams.
  • FileHash[obj,] effectively extracts data at the specified range of byte positions in the stream obj, ignoring any previous stream position.
  • FileHash[File["file"],] is also supported.
  • Possible formats include:
  • "Integer"integer (default)
    "DecimalString"decimal string
    "HexString"hexadecimal string
    "Base36String"base-36 alphanumeric string
    "Base64Encoding"Base64 encoding
    "ByteArray"hash code as an explicit byte array

Examples

open allclose all

Basic Examples  (3)

The fingerprint of a file:

In[5]:=
Click for copyable input
Out[5]=

The "SHA512" hash code of a file:

In[1]:=
Click for copyable input
Out[1]=

The "MD5" hash code in hexadecimal form:

In[1]:=
Click for copyable input
Out[1]=

Scope  (7)

Properties & Relations  (10)

See Also

FileSize  FileByteCount  FileDate  Hash  BinaryReadList  FileFormat

Introduced in 2007
(6.0)
| Updated in 2018
(11.3)