ARTICLE

How to implement HMACSHA1 one way algorithm in VB.NET

Posted by Shalini Juneja Articles | Cryptography in VB.NET May 17, 2011
In this article you learn that how you can use HMACSHA1 one way encryption algorithm to encrypt the text with the help of a public Key.
Download Files:
 
Reader Level:


Introduction

Here in this article we are discussing about Cryptographic HMACSHA1 one way algorithm. Its feature is Encryption. It is only used for Encryption not used for decryption. It encrypts Text with the help of a Public key. Firstly you enter  Text in the TextBox that you want to encrypt and then enter Public key known to everyone and press Text After Encryption Button you will get Encrypted Text. The implementation of example needs three TextBox and one Button control.


Getting Started

  • Simply Create a new Windows application.
  • Drag three TextBox and one Button on your form. Your form will look like below.

    HMACSHA1.gif
     
  • Then add the Below code.

       
    Private Sub encrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles encrypt.Click
            Dim algohmacsha1 As New HMACSHA1(Encoding.ASCII.GetBytes(getenckey.Text))
            Dim algohashValue As Byte() = algohmacsha1.ComputeHash(Encoding.ASCII.GetBytes(getval.Text))
            getres.Text = GetBytesToHexadeciString(algohashValue)
            algohmacsha1.Clear()
        End Sub
        Private Function GetBytesToHexadeciString(ByVal bytes As Byte()) As String
            Dim output As String = String.Empty
            Dim i As Integer = 0
            Do While i < bytes.Length
                output += bytes(i).ToString("X2")
                i += 1
            Loop
            Return output
        End
    Function

     
  • Now run your application.
Output:-

HMACSHA12.gif

HMACSHA13.gif

HMACSHA14.gif

Summary

In this article you learned that how to use HMACSHA1 one way algorithm.

Login to add your contents and source code to this article
share this article :
post comment
 

Hi, nice article.. but is there anyway to decode the encrypted text?

Posted by Rizky Aqew Aug 17, 2011
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor