How To Get The MD5 Hash Of A File In VB.NET

MD5 UPTUTORIALS
MD5 is a widely used cryptographic algorithm that produces a 128-BIT hash value. I think all the files you have in your computer has a unique md5 hash.. in some virus scanning process the files get identified easily with the hash value. Today we are going to make a simple application that will help you to get the md5 hash of any file.

Start a new project and do the traditions lol.. you must add a button, a label and a textbox.

user interface :)

You must add these namespaces before you could do any coding :

Imports System.Security.Cryptography
Imports System.IO
Imports System.Text

Here's the code for the application it's all under button click event.. I have explained the basic things by small comments.

  'creating the openfiledialog
        Dim Open As OpenFileDialog = New OpenFileDialog
        Open.Filter = "All Files (*.*)|*.*"
        If (Open.ShowDialog() = DialogResult.OK) Then TextBox1.Text = Open.FileName
        If Open.FileName = "" Then Exit Sub

        'accessing file & getting the hash
        Dim RD As FileStream = New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
        RD = New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
        Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
        md5.ComputeHash(RD)
        RD.Close()

        'converting the bytes into string
        Dim hash As Byte() = md5.Hash
        Dim SB As StringBuilder = New StringBuilder
        Dim HB As Byte
        For Each HB In hash
            SB.Append(String.Format("{0:X1}", HB))
        Next
        LabelHash.Text = "MD5 : " & SB.ToString()

The usage is pretty easy all you have to do is select and load the file from the button and you will get the Md5 hash for the selected file in the Label.

How To Use TinyURL API In VB.NET

TinyURL Icon Ultimate Programming TutorialsTinyURL is a URL shortening service a web service that provides short URLs for redirection of long URLs. This can be achieved very easily in PHP, I posted a PHP snippet about this you could reach it from here. Last year I created a TinyURL shortener I named it TinyURL Desktop App you can download it from here if you want. I found the source code of TinyURL Desktop App just now that's why I am writing this hehe. I used Devcomponents in my TinyURL Desktop App also I didn't handle exceptions because I was a noob then :0.

Cryptographic Algorithms For VB.NET



I wanted to share some Cryptographic Algorithms with you all and by the way cryptographic is a very important resource for programmers all the way .

Triple DES - triple data encryption (3DES)

Imports System.Text
Imports System.Security.Cryptography

Public Class 3_DES
    Public Shared Function Encrypt(ByVal toEncrypt As String, ByVal key As String, ByVal useHashing As Boolean) As String
  Dim keyArray As Byte()
  Dim toEncryptArray As Byte() = UTF8Encoding.UTF8.GetBytes(toEncrypt)

  If useHashing Then
    Dim hashmd5 As New MD5CryptoServiceProvider()
    keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key))
  Else
    keyArray = UTF8Encoding.UTF8.GetBytes(key)
  End If

  Dim tdes As New TripleDESCryptoServiceProvider()
  tdes.Key = keyArray
  tdes.Mode = CipherMode.ECB
  tdes.Padding = PaddingMode.PKCS7

  Dim cTransform As ICryptoTransform = tdes.CreateEncryptor()
  Dim resultArray As Byte() = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length)

  Return Convert.ToBase64String(resultArray, 0, resultArray.Length)
    End Function
End Class