Releases Encryption programming under the .NET architecture

xiaoxiao2021-03-06  117

Yesky (Zhang Yue ■ YESKY)

Http://www.yesky.com/softchannel/72342380484755456/20031225/1756613.shtml

I have always wanted to write a encrypted program for a long time, but I have always feel too much, but I don't have to do it, but I found the .NET's frame in the process of study .NET in the course of the .NET framework. And it is easy to encrypt in .NET. It is now explained to the encryption technology used in this article. First we have to know that the key is a dedicated noun. The key can be understood this way: x y = z. Where x is the data to be encrypted, Y is the key, z is encrypted data. If Y is yet in this addition, it will become x = z. So Y is here to be seen as a variable, and the key is also a variable. When this variable is changed, the encrypted data has changed more. However, it will be called vector in some information. The encryption method used herein is a method called a keytric value. This method is to combine data and keys to be encrypted to generate new encrypted data. In .NET, all the classes you want to use are all concentrated in the System.Security.cryptography framework, and he contains a variety of encryption algorithms, so our encryption methods we use are also in the System.Security.cryptography box. Let's take a look at how to achieve data encryption. First add a Button, 3 TextBox, 3 Label controls in the window. Setting the button's Text property to "OK". Setting the text attribute settings of 3 Label controls to: text, key, hmacsha1.3 TextBox properties remain default. After adding controls, the figure is as follows: Now double-click Button1 Enter the following code in Button1_Click:

Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim txt1 () As Byte txt1 = System.Text.ASCIIEncoding.ASCII.GetBytes (TextBox1.Text) 'read the character input , That is, the text to be encrypted. DIM Key (16) as byte key = system.text.asciiencoding.ascii.getbytes (TextBox2.text) 'Read Key' Hmacsha Encycry DIM HMA As New System.Security.cryptography.hmacsha1 (KEY) 'Nurse Encryption Class, both what encryption method Dim csstream as used New System.Security.Cryptography.CryptoStream (System.IO.Stream.Null, hma, Security.Cryptography.CryptoStreamMode.Write) 'encrypted converted csstream.Write (txt1, 0, txt1. Length) 'Save the encrypted data in TXT1 in this variable' This time TXT1 is not the previous text, but is refreshed after encrypted data. CSStream.close () textBox3.text = system.text.asciiencoding.ascii.getstring (hma.hash) 'Displays the encrypted text. End Sub

转载请注明原文地址:https://www.9cbs.com/read-98907.html

New Post(0)