Calculate-file-Hash-using-MD5-SHA1-SHA256-SHA512 - WeOnlyDo Software example code



All

wodCrypt (12)
wodSSH (10)
wodSFTP (23)
wodSSHServer (1)
wodSSHTunnel (11)
wodSSHpackage
wodSFTPdll

wodSSH.NET (10)
wodSFTP.NET (24)
wodFtpDLX.NET (22)
wodWebServer.NET (10)

wodAppUpdate (13)
wodHttpDLX (8)
wodFtpDLX (22)
wodTelnetDLX
wodFTPServer (3)
wodWebServer (10)
wodVPN
wodXMPP (13)
All ** [Visual Basic] ** [C#] ** [VB.NET] **

Calculate file Hash using: MD5, SHA1, SHA256 and SHA512
VB code
Dim wodCrypt1 As wodCryptCom
Set wodCrypt1 = New wodCryptCom
Dim srcfile As New FileBlob
Dim destfile As New FileBlob

'Calculate MD5 hash.
wodCrypt1.Type = MD5
srcfile.FileName = "c:\somefile.exe" 'Load file in FileBlob.
wodCrypt1.Digest srcfile, destfile
Debug.Print "MD5: " & destfile.ToHex

'Calculate SHA1 hash.
wodCrypt1.Type = SHA1
srcfile.FileName = "c:\somefile.exe"
wodCrypt1.Digest srcfile, destfile
Debug.Print "SHA1: " & destfile.ToHex

'Calculate SHA256 hash.
wodCrypt1.Type = SHA256
srcfile.FileName = "c:\somefile.exe"
wodCrypt1.Digest srcfile, destfile
Debug.Print "SHA256: " & destfile.ToHex

'Calculate SHA512 hash.
wodCrypt1.Type = SHA512
srcfile.FileName = "c:\somefile.exe"
wodCrypt1.Digest srcfile, destfile
Debug.Print "SHA512: " & destfile.ToHex
VB.NET code
Dim wodCrypt1 As WODCRYPTCOMLib.wodCryptCom
wodCrypt1 = New WODCRYPTCOMLib.wodCryptCom
Dim srcfile As New WODCRYPTCOMLib.FileBlob
Dim destfile As New WODCRYPTCOMLib.FileBlob

'Calculate MD5 hash.
wodCrypt1.type = WODCRYPTCOMLib.CryptoTypes.MD5
srcfile.FileName = "c:\somefile.exe" 'Load file in FileBlob.
wodCrypt1.Digest(srcfile, destfile)
Console.WriteLine("MD5: " & destfile.ToHex)

'Calculate SHA1 hash.
wodCrypt1.type = WODCRYPTCOMLib.CryptoTypes.SHA1
srcfile.FileName = "c:\somefile.exe"
wodCrypt1.Digest(srcfile, destfile)
Console.WriteLine("SHA1: " & destfile.ToHex)

'Calculate SHA256 hash.
wodCrypt1.type = WODCRYPTCOMLib.CryptoTypes.SHA256
srcfile.FileName = "c:\somefile.exe"
wodCrypt1.Digest(srcfile, destfile)
Console.WriteLine("SHA256: " & destfile.ToHex)

'Calculate SHA512 hash.
wodCrypt1.type = WODCRYPTCOMLib.CryptoTypes.SHA512
srcfile.FileName = "c:\somefile.exe"
wodCrypt1.Digest(srcfile, destfile)
Console.WriteLine("SHA512: " & destfile.ToHex)
C# code
WODCRYPTCOMLib.wodCryptCom wodCrypt1;
wodCrypt1 = new WODCRYPTCOMLib.wodCryptCom();
WODCRYPTCOMLib.FileBlob srcfile = new WODCRYPTCOMLib.FileBlob();
WODCRYPTCOMLib.FileBlob destfile = new WODCRYPTCOMLib.FileBlob();

//Calculate MD5 hash.
wodCrypt1.type = WODCRYPTCOMLib.CryptoTypes.MD5;
srcfile.Filename = "c:\\somefile.exe"; //Load file in FileBlob.
wodCrypt1.Digest((WODCRYPTCOMLib.Blob)srcfile, (WODCRYPTCOMLib.Blob)destfile);
Console.WriteLine("MD5: " + destfile.ToHex());

//Calculate SHA1 hash.
wodCrypt1.type = WODCRYPTCOMLib.CryptoTypes.SHA1;
srcfile.Filename = "c:\\somefile.exe";
wodCrypt1.Digest((WODCRYPTCOMLib.Blob)srcfile, (WODCRYPTCOMLib.Blob)destfile);
Console.WriteLine("SHA1: " + destfile.ToHex());

//Calculate SHA256 hash.
wodCrypt1.type = WODCRYPTCOMLib.CryptoTypes.SHA256;
srcfile.Filename = "c:\\somefile.exe";
wodCrypt1.Digest((WODCRYPTCOMLib.Blob)srcfile, (WODCRYPTCOMLib.Blob)destfile);
Console.WriteLine("SHA256: " + destfile.ToHex());

//Calculate SHA512 hash.
wodCrypt1.type = WODCRYPTCOMLib.CryptoTypes.SHA512;
srcfile.Filename = "c:\\somefile.exe";
wodCrypt1.Digest((WODCRYPTCOMLib.Blob)srcfile, (WODCRYPTCOMLib.Blob)destfile);
Console.WriteLine("SHA512: " + destfile.ToHex());