Encrypting Text using SHA and MD5 Hash Encryption.

This program encrypts the text or the word you type in the textbox to SHA(Secure Has Algorithm) and MD5(Message Digest).

What is Encryption?

“Encryption, the process of scrambling a message or other information so that it cannot be easily read, is one of the most critical parts to the security puzzle. If you have the best firewall, very tight security policies, hardened operating systems, virus scanners, intrusion-detection software, antispyware, and every other computer security angle covered but send your data in raw, plain text, then you simply are not secure.”

Now, we are going to create a program that converts the plain text into scrambled text using the said process of encryption. Let’s begin.

Step 1:

Create a form, add 3 Label, 3 Textbox and 2 Buttons. To make it a multiline textbox just click the arrow and check the Multiline. See the image below .



Step 2:
The first textbox – Textbox1, second – Textbox2, third – Textbox3.
In the name property change the first button – btnEncrypt, second button – btnEncryptMD5

Copy the code


Imports System.Text
Imports System.Security.Cryptography

Public Class frmEncrypt
    Dim MD5 As MD5CryptoServiceProvider
    Dim d As New System.Security.Cryptography.TripleDESCryptoServiceProvider
    Dim h As New System.Security.Cryptography.MD5CryptoServiceProvider
    Private Sub btnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click
        TextBox2.Text = SHA512(TextBox1.Text)
    End Sub

    Private Function SHA512(ByVal SourceText As String)
        Dim a() As Byte = Encoding.UTF8.GetBytes(SourceText)
        Dim b As Byte()
        Dim c As New SHA512Managed
        b = c.ComputeHash(a)
        Dim d As String = BitConverter.ToString(b)
        Return d
    End Function

    Function MD5Hash(ByVal value As String) As Byte()
        Return MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(value))
    End Function

    Private Sub btnEncryptMD5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncryptMD5.Click
        Try
            d.Key = h.ComputeHash(Encoding.Default.GetBytes(TextBox1.Text))
            d.Mode = Security.Cryptography.CipherMode.ECB
            Dim encrypt As System.Security.Cryptography.ICryptoTransform = d.CreateEncryptor
            Dim b As Byte() = Encoding.Default.GetBytes(TextBox1.Text)
            Dim c As String = Convert.ToBase64String(encrypt.TransformFinalBlock(b, 0, b.Length))
            TextBox3.Text = c
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class

Final Output:


Encrypting Text using SHA and MD5 Hash Encryption. Encrypting Text using SHA and MD5 Hash Encryption. Reviewed by code-dev on 10:36 PM Rating: 5

No comments:

Powered by Blogger.