File Hash
Calculates a cryptographic hash value from file contents using various hash algorithms. File hashing creates unique fingerprints for files, enabling integrity verification, duplicate detection, and change monitoring.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- File Path - Path to the file to hash. Can be absolute or relative path.
Options
- Hash Function - The cryptographic hash algorithm to use:
- md5 - MD5 (128-bit) - Fast, commonly used for checksums
- sha1 - SHA-1 (160-bit) - Legacy, use SHA-256+ for security
- sha256 - SHA-256 (256-bit) - Recommended for integrity verification
- sha512 - SHA-512 (512-bit) - Higher security, larger output
- blake256 - BLAKE-256 (256-bit) - Fast alternative to SHA-256
- blake512 - BLAKE-512 (512-bit) - Fast alternative to SHA-512
- whirlpool - Whirlpool (512-bit) - High security hash function
Output
- hash - The computed hash value in hexadecimal format.
How It Works
The File Hash node processes file contents to generate cryptographic hashes:
- Opens the specified file for reading
- Reads file content based on algorithm:
- SHA-1, SHA-256, SHA-512, MD5: Stream-based reading (memory efficient)
- BLAKE-256, BLAKE-512, Whirlpool: Load entire file into memory
- Applies the selected hash algorithm to file bytes
- Encodes the hash output as hexadecimal string
- Closes the file and returns the hash value
Stream-based hashing is more memory efficient for large files.
Example Usage
Verify File Integrity
// Calculate file hash after download
const downloadedFile = "C:/Downloads/software-installer.exe";
// Use File Hash node with SHA-256
const fileHash = "{{msg.hash}}";
// Compare with official hash from vendor website
const officialHash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
if (fileHash === officialHash) {
console.log("File integrity verified - safe to install");
} else {
console.log("WARNING: File may be corrupted or tampered with!");
}
Detect File Duplicates
// Find duplicate files in a folder
const files = [
"C:/Documents/report_v1.pdf",
"C:/Documents/report_v2.pdf",
"C:/Documents/report_final.pdf"
];
const hashes = {};
// Use ForEach to iterate files
// Use File Hash node for each file
const currentHash = "{{msg.hash}}";
if (hashes[currentHash]) {
console.log("Duplicate found: " + currentFile + " = " + hashes[currentHash]);
} else {
hashes[currentHash] = currentFile;
}
Monitor File Changes
// Detect if configuration file has been modified
const configFile = "/etc/app/config.json";
// Use File Hash node
const currentHash = "{{msg.hash}}";
// Load stored hash from database
const storedHash = "{{db.config_hash}}";
if (currentHash !== storedHash) {
console.log("Configuration file has been modified");
// Trigger reload or alert
// Update stored hash
}
Verify Backup Integrity
// Verify backup files haven't been corrupted
const backupFile = "/backups/database_2024_01_15.sql";
// 1. Use File Hash node after creating backup
const backupHash = "{{msg.hash}}";
// 2. Store hash in backup catalog
// backups.push({file: backupFile, hash: backupHash, date: Date.now()});
// 3. Later, verify backup integrity before restore
// Hash file again and compare with stored hash
Create File Manifest
// Generate manifest file with hashes for all files
const projectFiles = ["index.js", "app.css", "config.json"];
const manifest = [];
// Use ForEach to iterate files
// For each file:
// 1. Use File Hash node with SHA-256
// 2. Add to manifest: {file: filename, hash: hash}
// Write manifest.json with all file hashes
// manifest = [
// {file: "index.js", hash: "a1b2c3..."},
// {file: "app.css", hash: "d4e5f6..."},
// {file: "config.json", hash: "g7h8i9..."}
// ]
Verify File After Transfer
// Verify file integrity after FTP/SFTP transfer
// 1. Calculate hash before upload
const sourceFile = "/local/data/export.csv";
// Use File Hash node
const sourceHash = "{{msg.hash}}";
// 2. Upload file via FTP
// 3. Download file to temp location
// 4. Calculate hash of downloaded file
const downloadedHash = "{{msg.hash}}";
// 5. Compare hashes
if (sourceHash === downloadedHash) {
console.log("File transferred successfully");
}
Requirements
- Valid file path that exists and is readable
- Read permissions for the file
- Sufficient memory for BLAKE and Whirlpool algorithms (load entire file)
- File must not be locked by another process
Error Handling
The node will return errors in the following cases:
- File not found - File doesn't exist at specified path
- Access denied - No read permission for the file
- File locked - File is exclusively locked by another process
- Memory error - File too large for available memory (BLAKE/Whirlpool)
- I/O error - Disk read error or file system issue
Hash Algorithm Comparison
Security Level
- Cryptographically Broken: MD5, SHA-1 (use for checksums only)
- Secure: SHA-256, SHA-512, BLAKE-256, BLAKE-512, Whirlpool
Memory Efficiency
- Stream-based (low memory): MD5, SHA-1, SHA-256, SHA-512
- Load entire file: BLAKE-256, BLAKE-512, Whirlpool
Speed (Fastest to Slowest)
- MD5
- SHA-1
- BLAKE-256
- SHA-256
- BLAKE-512
- SHA-512
- Whirlpool
Output Size
- MD5: 32 hex characters (128 bits)
- SHA-1: 40 hex characters (160 bits)
- SHA-256, BLAKE-256: 64 hex characters (256 bits)
- SHA-512, BLAKE-512, Whirlpool: 128 hex characters (512 bits)
Recommendations by Use Case
- Large Files (over 100MB): SHA-256 or SHA-512 (stream-based)
- File Integrity: SHA-256 (best balance)
- Quick Checksums: MD5 (fast but not secure)
- High Security: SHA-512 or Whirlpool
- Performance Critical: BLAKE-256 (fast and secure)
- Legacy Compatibility: MD5 or SHA-1
Common Use Cases
- File Integrity Verification - Verify downloaded files haven't been corrupted
- Duplicate Detection - Find duplicate files by comparing hashes
- Change Monitoring - Detect when files have been modified
- Backup Verification - Ensure backup files are intact
- Software Distribution - Provide checksums for downloads
- Compliance - Maintain file integrity records for audits
- Version Control - Track file versions using hashes
- Deduplication - Optimize storage by identifying identical files
Performance Considerations
- File size: Hashing time increases linearly with file size
- Algorithm choice:
- Use SHA-256/512 for large files (stream-based)
- BLAKE algorithms faster for small-to-medium files
- Disk speed: I/O bound for large files - SSD vs HDD matters
- Parallel processing: Can hash multiple files in parallel
- Caching: Cache hashes for frequently verified files
Performance Tips
- Use MD5 for quick checksums when security isn't critical
- Choose SHA-256/512 for files larger than 100MB
- Process multiple files in parallel using parallel flow execution
- Cache file hashes with file modification timestamp
- Use incremental hashing for very large files in chunks
Security Best Practices
- Use SHA-256 or higher - Avoid MD5/SHA-1 for security applications
- Verify hashes from trusted source - Compare with official checksums
- Store hashes securely - Protect hash manifests from tampering
- Use HMAC for authentication - For authenticated file hashes
- Re-verify periodically - Check archived files haven't been corrupted
- Hash before encryption - Verify integrity before encrypting files
Tips for Effective Use
- Choose algorithm based on file size and security requirements
- Store hashes in database or manifest file for later verification
- Include file metadata (size, date) along with hash for complete verification
- Use consistent hash algorithms across your application
- Automate integrity checks for critical files
- Consider using File Hash before and after encryption
- Test with known file hashes to verify correctness
Troubleshooting
Hash Calculation Fails
- Check file exists - Verify file path is correct
- Verify permissions - Ensure read access to file
- File locked - Close applications using the file
- Memory issues - Use stream-based algorithms (SHA) for very large files
Different Hashes for Same File
- File modified - Check file modification timestamp
- File corruption - File may have been partially corrupted
- Different algorithms - Ensure using same hash algorithm for comparison
- Platform differences - Binary files should hash identically, text files check line endings
Performance Issues
- Large files - Use SHA-256/512 instead of BLAKE/Whirlpool for better memory efficiency
- Slow disk - Hash calculation limited by disk read speed
- Many small files - Process in parallel batches
Example Workflows
File Integrity System
// 1. Create hash catalog during backup
const filesToBackup = ["file1.dat", "file2.dat", "file3.dat"];
const catalog = [];
for (const file of filesToBackup) {
// Use File Hash node
catalog.push({
file: file,
hash: "{{msg.hash}}",
size: fileSize,
date: Date.now()
});
}
// 2. Verify integrity before restore
for (const entry of catalog) {
// Use File Hash node on entry.file
if ("{{msg.hash}}" !== entry.hash) {
console.log("Corrupted: " + entry.file);
}
}
Related Nodes
- Text Hash - Calculate hash of text content
- HMAC Signature - Create authenticated file hashes
- Encrypt File - Encrypt files after hashing
- Sign - Create digital signatures for files