The FILE_HASH function returns a hash checksum string for a given file. The checksum is constructed by running all of the file bytes through a cryptographic hash algorithm, and produces a string of hexadecimal characters of a certain length. These algorithms all have the property that small changes to a file (or two different files) will produce large differences in the resulting checksums. These hashes are useful for confirming that a file has not been altered or corrupted. By default, the MD5 hash algorithm is used but you can choose different algorithms via keywords.

Example


IDL> file = filepath('hdf5_test.h5', subdir=['examples', 'data'])
IDL> print, file_hash(file)
69121a6aa9bc4eed8bdbd668f98d5503
 
IDL> print, file_hash(file, /SHA256)
74e416059b19e63581f9d8d03266081ed6a9a9a18fa44c2e41709ff7a7c20dba

Syntax


Result = FILE_HASH( File, /MD5, /SHA1, /SHA256, /SHA512)

Return Value


Returns a scalar string or string array containing the hexadecimal hash for each file. If File is a string array then the result will be a string array of the same dimensions, where each element contains the hash for the corresponding file.

Arguments


File

A scalar string or string array containing the full paths to the file or files to be hashed. If File is a string array then each element is hashed individually and the result is a string array of the same dimensions, where each element contains the hash for the corresponding file.

Keywords


MD5

Set this keyword to use the 128-bit MD5 algorithm and return a 32-character hash. This is the default.

SHA1

Set this keyword to use the 160-bit SHA-1 algorithm and return a 40-character hash.

SHA256

Set this keyword to use the 256-bit SHA-2 algorithm and return a 64-character hash.

SHA512

Set this keyword to use the 512-bit SHA-2 algorithm and return a 128-character hash.

Version History


9.2

Introduced

See Also


IDL_HASHVAR, IDL_String::Decrypt/Encrypt