I am trying to perform a SHA-256 hash of all files in a folder via LabVIEW.
I found this link: https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha256managed?view=net-5.0
So I thought I would try to incorporate this in my LabVIEW code. I have no experience calling .dlls through LabVIEW or incorporating .NET in my VIs.
I could access the SHA256Managed Class by starting a Constructor Node in LabVIEW, selecting mscorlib(184.108.40.206): In my case this was under C:\Windows\Microsoft.NET\Framework\v2.0.50727
I thought now all I had to do is go back to the original link (from microsoft, linked above) and look at the properties, methods and etcetera to find out how to select the folder and which method would give me the hash.
I concluded (perhaps wrongly) that I would need to use ComputeHash (to get the results) with an inputStream which would reference to the folder I want to perform the SHA-256 hash on. However, I can't figure out how to pass on a reference to which folder I should select, because no matter what I do, I can't pass on a folder path to inputStream!
What am I doing wrong?
Any help would be greatly appreciated
Solved! Go to Solution.
If you have LabVIEW 2020, you can use the integrated File Checksum (File >> Adv File Funcs >> File Checksum.vi).
If not, use Read Binary File to read the content of each file and use the "buffer" overload for ComputeHash. (Or create a DotNet FileStream object from the path).
To get the hash of the folder, you could concatenate the individual hashes and use ComputeHash once more.
Thanks for the reply, I have done it for a single file, and when I convert my array containing the result to a string, I get a weird result:
This is my code
Any suggestions of what is wrong?
Also don't forget to Close the .Net refnum. Otherwise the object will stay in memory as long as your application is running. If you then executed this code multiple times, every time a new object will be created.
Ok, now the last weird thing is that when comparing the result of my hash vs some online hash tools, I get different results, but all online tools have the same results.
Any idea why?
Make sure you are reading the whole file, not just a single character 😉
And adding to what rolfk said, close the file reference from read binary file.