vb.net2008 instance writing and decryption program

Source: Internet
Author: User
Tags decrypt decrypt text

The main development environment for this article is that the Visual Studio 2008,visual Studio series has always provided powerful control capabilities, but we can use these controls to write powerful applications that visual Studio2008 has also made a number of improvements in some features. This article mainly uses the latest. NET development tools of Microsoft to show the application methods of text encryption and decryption, and introduces some techniques for creating basic encryption and decryption programs. Very suitable for the beginners of the. NET development tools, has certain practical value.

Open Visual Studio 2008 on the File menu, click New Project. In the Templates pane of the New Project dialog box, click Windows Application (Windows application). Click OK (OK) as shown in Figure 1.

Select the Form1 form and add the following controls to the Form1 form: Label1, Label2, Label3 controls, TextBox1, TextBox2, TextBox3 controls, Button1, and Button2 controls.

The related properties are set as follows:

We adjust the interface appropriately, the interface setting effect is as follows: Figure 2

After the program interface is set up, we need to create the class, in the class to enter the code related to this program

Select < Project >---< add Class >---file named: Csmode Figure 3

Before programming, first we need to know the System.Security.Cryptography namespace

System.Security.Cryptography namespaces provide cryptographic services, including secure data encoding and decoding

Introduction to some commonly used enumerations

Introduction to some commonly used enumerations to enter the Csmode.vb class code event

Input code:

Imports System

Imports System.IO

Imports System.Security.Cryptography

Imports System.Text

Public Class Csmode

Public Function Encrypt (ByVal strinput As String) as String

Dim byteinput as [Byte] () = Encoding.Default.GetBytes (strinput)

Dim MS as New System.IO.MemoryStream

Dim DESC as New DESCryptoServiceProvider

Dim Cstream as New CryptoStream (MS, DESC. CreateEncryptor (Encoding.Default.GetBytes ("20000000"), Encoding.Default.GetBytes ("number of bytes"), CryptoStreamMode.Write)

Cstream.write (byteinput, 0, Byteinput.length)

Cstream.flushfinalblock ()

Return convert.tobase64string (Ms. ToArray ())

End Function

Public Function Decrypt (ByVal strinput As String) as String

Dim byteinput as [Byte] () = convert.frombase64string (strinput)

Dim MS as New System.IO.MemoryStream

Dim DESC as New DESCryptoServiceProvider

Dim Cstream as New CryptoStream (MS, DESC. CreateDecryptor (Encoding.Default.GetBytes ("20000000"), Encoding.Default.GetBytes ("number of bytes"), CryptoStreamMode.Write)

Cstream.write (byteinput, 0, Byteinput.length)

Cstream.flushfinalblock ()

Return Encoding.Default.GetString (Ms. ToArray ())

End Function

End Class

Select Form1 form to enter the Code Editor

Make a declaration first

Imports System

Imports System.IO

Imports System.Text

Public Class Form1

Inherits System.Windows.Forms.Form

Enter Button1_Click event

Private Sub button1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click

Dim Encode as New Csmode () to encrypt text

TextBox2.Text = Encode.encrypt (TextBox1.Text)

End Sub

Enter Button2_Click Event

Private Sub button2_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button2.click

Dim Decode as New Csmode () to decrypt text

TextBox3.Text = Decode.decrypt (TextBox2.Text)

End Sub

After the code is entered, run the program to test. As shown in Figure 4

The success of the program, the above is a simple text encryption and decryption process, I hope you can extrapolate, using this idea can be compiled to write more powerful encryption and decryption procedures.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.