DOTNET.FILE_CHECKSUM compute checksum has of file
function hash = file_checksum(file, hash_method)
arguments
file (1,1) string
hash_method (1,1) string
end
if any(strcmp(hash_method, {'sha256', 'SHA256'}))
hash_method = "SHA-256";
end
file_chunk = 10e6;
fid = fopen(file, 'r');
assert(fid > 1, "could not open file %s", file)
inst = System.Security.Cryptography.HashAlgorithm.Create(hash_method);
while ~feof(fid)
inst.ComputeHash(fread(fid, file_chunk, '*uint8'));
end
h = uint8(inst.Hash);
fclose(fid);
hash = sprintf('%.2x', h);
end