HMACSHA1 algorithm in VB.NET

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.
  • 5378


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.

  • 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)
        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
            Return output
        End Function

  • Now run your application.





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


More Articles

© 2020 DotNetHeaven. All rights reserved.