Encrypting a Text in VB.NET

Encrypting is the translation of data into a secret code. Encryption is the most effective way to achieve data security. And for now we will create a program that can encrypt an inputted text. Now, let's start this Font Dialog tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add one TextBox name TextBox1 for inputting a text, one label named lblOutput that will be used for displaying the output, and one Button named for encrypting the inputted text and will be displayed in the Label. You must design your layout like this: design 4. Now put this code in your code module.
  1. Imports System.Security.Cryptography
  2. Imports System.Text
  3. Public Class Form1
  4. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  5. Dim encryptMD5 As New MD5CryptoServiceProvider()
  6. Dim encryptedText As Byte()
  7. Dim encoder As New UTF8Encoding()
  8. encryptedText = encryptMD5.ComputeHash(encoder.GetBytes(TextBox1.Text))
  9. lblOuput.Text = Convert.ToBase64String(encryptedText)
  10.  
  11. End Sub
  12. End Class

Explanation:

We have imported System.Security.Cryptography and System.Text. The System.Security.Cryptography namespace provides cryptographic services, including secure encoding and decoding of data, as well as many other operations, such as hashing, random number generation, and message authentication. And the System.Text namespace contains classes that represent ASCII and Unicode character encodings; abstract base classes for converting blocks of characters to and from blocks of bytes; and a helper class that manipulates and formats String objects without creating intermediate instances of String. We initialized variable encryptMD5 As New MD5CryptoServiceProvider() to provide encryption or cryptographic services, variable encryptedText As Byte() to get the Byte of a certain text, and variable encoder As New UTF8Encoding() for using a Unicode character encodings. Next, the encryptedText gets the byte of the Hash of encryptMD5 and the UTF8Encoding of the TextBox1. Then the output will display at lblOutput that the encryptedText was converted into Base64String.

Output:

output Download the source code below and try it! :) For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below and hire me. Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Comments

Submitted byAqie (not verified)on Mon, 03/10/2014 - 16:45

sir pde po ba tong gamitin para sa connection string para secured at kung merun din kayong method to decode.

Add new comment