Check File
Checks if a file hash matches the provided hash code, calculating the hash with the selected hash function.
Command availability: IBM RPA SaaS and IBM RPA on premises
Description
The command checks if a file matches the provided hash code by calculating the hash by using one of the available hash functions.
Script syntax
IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.
hashTest [--isfromfile(Boolean)] --hashfile(String) --hashstring(String) --filename(String) [--type(HashType)] (Boolean)=value
Limitations
The following algorithms are not available in environments with FIPS encryption enabled:
- CRC32
- MD5
- RIPEMD-160
Input parameters
The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.
Designer mode label | Script mode name | Required | Accepted variable types | Description |
---|---|---|---|---|
Use File | isfromfile |
Optional |
Boolean |
Enable it to provide a file that contains the hash code to compare the result. |
Hash File | hashfile |
Required when File is enabled |
Text |
Full path to the file that contains the hash code to compare to the source file. |
Hash Text | hashstring |
Required when Use File is not enabled |
Text |
Provide a text with the hash code to compare the result. |
File Name | filename |
Required |
Text |
Full path to the file. |
Algorithm | type |
Optional |
HashType |
Hash function used to calculate the hash. For more information see the type parameter options. |
type
parameter options
Algorithm | Description |
---|---|
CRC32 | A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data. It was developed by Hewlett-Packard in 1961 and is still widely used today. CRC32 is a 32-bit checksum algorithm that uses a polynomial division remainder to detect errors in data. |
MD5 | MD5 Message-Digest Algorithm is a cryptographic hash function that takes an input and produces a 128-bit hash value. It is a widely used hash function and is used to verify the integrity of data. MD5 is a one-way hash function, which means it is easy to compute the hash value for any given input, but it is computationally expensive to reverse the hash value back to the original input. |
RIPEMD-160 | RIPEMD-160 is a cryptographic hash function that produces a 160-bit hash value. It is designed to be faster than SHA-1 and has been proven to have better security properties. RIPEMD-160 is a variant of the RIPEMD family of hash functions, which includes RIPEMD-128, RIPEMD-160, and RIPEMD-256. |
SHA-1 | SHA-1 is a cryptographic hash function that produces a 160-bit hash value. It is a secure hash algorithm and is widely used in cryptography and computer security. SHA-1 is a variant of the Secure Hash Standard (SHS), which was published by NSA in 1993. |
SHA-256 | SHA-256 is a cryptographic hash function that produces a 256-bit hash value. It is a successor to SHA-1 and is considered to be more secure than SHA-1. It is a member of the SHA-2 family of hash functions. |
SHA-384 | SHA-384 is a cryptographic hash function that produces 384-bit hash values. It is a member of the SHA-2 family of hash functions. |
SHA-512 | SHA-512 is a cryptographic hash function that produces 512-bit hash values. It is a member of the SHA-2 family of hash functions. |
Output parameters
Designer mode label | Script mode name | Accepted variable types | Description |
---|---|---|---|
Result | value |
Boolean |
Returns True if the file matches the hash code, otherwise returns False . |
Example
Example 1: The following example uses the MD5 algorithm to calculate the hash and uses a the hash code as plain text to compare to the file.
defVar --name matchesTheHash --type Boolean
defVar --name filePath --type String
//Import of file to be verified.
import --name file --type "File" --content V0RHIEF1dG9tYXRpb24= --extension ".txt"
export --asset "${asset.file}" filePath=value
//Check file integrity according to hash "a58ec78ef0ecc22e6a8079b12727ebd6" of type MD5
hashTest --hashstring a58ec78ef0ecc22e6a8079b12727ebd6 --filename "${filePath}" --type "MD5" matchesTheHash=value
logMessage --message "File Matches Hash Code: ${matchesTheHash}" --type "Info"
//This example produces the following result:
//File Matches Hash Code: True
Example 2: The following example uses the MD5 algorithm to compare the contents of the "hashCodeFile" to the hash of the "file" variable.
defVar --name matchesTheHash --type Boolean
defVar --name filePath --type String
defVar --name hashCodeFile --type String
//Importing files.
import --name file --type "File" --content V0RHIEF1dG9tYXRpb24= --extension ".txt"
import --name hashCodeFile --type "File" --content YTU4ZWM3OGVmMGVjYzIyZTZhODA3OWIxMjcyN2ViZDY= --extension ".txt"
export --asset "${asset.file}" filePath=value
export --asset "${asset.hashCodeFile}" hashCodeFile=value
//Checks file integrity for hash inserted into another file using MD5 type.
hashTest --isfromfile --hashfile "${hashCodeFile}" --filename "${filePath}" --type "MD5" matchesTheHash=value
logMessage --message "File Matches Hash Code: ${matchesTheHash}" --type "Info"
// This example produces the following result:
// File Matches Hash Code: True