verifyFileIntegrity static method
验证文件完整性
Implementation
static Future<bool> verifyFileIntegrity(
String filePath, String expectedHash, HashAlgorithm algorithm) async {
try {
String actualHash;
switch (algorithm) {
case HashAlgorithm.md5:
actualHash = await calculateMD5(filePath);
break;
case HashAlgorithm.sha1:
actualHash = await calculateSHA1(filePath);
break;
case HashAlgorithm.sha256:
actualHash = await calculateSHA256(filePath);
break;
}
return actualHash.toLowerCase() == expectedHash.toLowerCase();
} catch (e) {
return false;
}
}