FileTools
Hash
compute a hash value for a file
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
Hash(filepath, opts)
filepath
-
string; the file or URL to be hashed
opts
zero or more options of the form method=value or output=value.
method=one of md4, md5, or sha1.
This specifies the hashing algorithm to use. The default value is md5.
output=one of string or integer
This specifies whether the output should be a string with a hexadecimal representation of the hashed value, or an integer. The default value is string.
The procedure Hash computes a hash, or message digest of the file s. By default, it uses the MD5 message digest algorithm. However, by using the method= option, you can select a different hashing algorithm. The available methods are: md4, md5 and sha1.
This hashed value is represented by a string that is a hexadecimal representation of the integer value of the hash.
The input can be a file or URL.
It is extremely unlikely that two distinct files of arbitrary length will produce the same hashed value.
file := FileTools:-JoinPath( ["images/rollercoaster.jpg"], base=datadir );
C:\Program Files\Maple 2016\data\images\rollercoaster.jpg
Compute an MD5 hash of this file.
FileTools:-Hash( file );
method = "md5", output = string
ad20d15e446e23ce8bb537f96720455c
Compute an MD4 hash of this file.
FileTools:-Hash( file, method=md4 );
method = md4, output = string
9733588532282617f53c026db00810a6
Compute an SHA1 hash of this file.
FileTools:-Hash( file, method=sha1 );
method = sha1, output = string
1af7332b4865b8254813bc07b068a92fe0d1381f
Return the SHA1 hash as an integer.
FileTools:-Hash( file, method=sha1, output=integer );
method = sha1, output = integer
153946501560413761515295793599215680815507781663
Fetch a file from a remote source and compute an SHA1 hash.
FileTools:-Hash( "http://www.maplesoft.com/data/examples/jpg/fingerprint.jpg", method="sha1" );
1c2c82bd2b358b7fd2acb7dfffe3b67662f183a5
The FileTools[Hash] command was introduced in Maple 2016.
For more information on Maple 2016 changes, see Updates in Maple 2016.
The FileTools[Hash] command was updated in Maple 2019.
See Also
StringTools[Hash]
Download Help Document