Safety first:. NET Encryption technology Guide (1)

Source: Internet
Author: User
Tags decrypt hash pack web services asymmetric encryption
Security | Encryption Summary:
Information security is one of the most important problems in computer application, but at present. There are few examples of net encryption capabilities. In view of this, this paper explores the. NET platform to encrypt/decrypt files, and provides a tool for encrypting/decrypting files.



The rapid development of Web services in an indisputable situation has prompted many units to begin to consider them. NET-like development platform. But for security concerns, some units are always wary of adopting new technologies. Fortunately, there are many sophisticated security and network technologies, such as virtual private networks (VPNs) and firewalls, that can greatly improve the security and performance of Web service applications, allowing developers the freedom to choose security technologies, rather than having to use the XML security technologies that are still evolving.

Although security is the primary issue of information systems, it is relevant. There are few examples of net security and encryption tools. Look at the majority. NET books, you can't find any questions about security, let alone the discussion of cryptography.

In view of this, this article will introduce how to use the. NET encryption and key generation classes in VB development, and provide a tool cryption that can be used to encrypt and decrypt files. With this tool, you can keep a variety of confidential files on your hard disk, such as all password/user name information, income and expenditure files, and other information that you want to keep confidential, and you can encrypt those that are sent over the Internet. The use of encryption technology is very extensive, you can further customize the tools provided in this article to meet certain special needs, such as increased batch processing capacity.



One or two types of important security threats

Attacks and leaks are two of the biggest security threats facing computers. An attack can come from a virus, for example, it can delete files, slow down the machine, or cause other security issues. In contrast, leaks tend to be much more covert, and it infringes your privacy: unauthorized access to hard disk files, interception of messages sent over the Internet, and so on. Leaks can also be accompanied by attacks, such as the modification of confidential documents.

The best precaution against leaks is encryption. Effective encryption not only eliminates the leak, but also guard against the attack caused by the leak. Cryptography is sometimes used for authentication in the process of communication--if a user knows the password, then he should be the person who owns the identity.

It must be stated, however, that there is no security technology that is safe from leaks, because passwords can be obtained by unauthorized people.



Second, use. The premise of net encryption function

First, you want to use. NET, you must use the Imports statement to introduce the encrypted package. Before you test any of the code involved in this article, add the following imports statement at the top of the VB code window:

Imports System.IO
Imports System.Text
Imports System.Security.Cryptography



Second, the US government used to restrict the export of certain cryptographic technologies. Although these restrictions are no longer valid,. NET Framework disables the Advanced encryption technology in the export version of Windows. If you have Windows without advanced encryption, you can download the update package from the Microsoft Web site: For Windows 2000, install the High Encryption Pack contained in Service Pack 2; for NT, install Service Pack 6a. For Windows ME, 95, 98 users, IE 5.5 also contains the high encryption Pack.



III. encryption/Decryption Tools overview

The tools provided in this article can be used to encrypt and decrypt files, and if you are anxious to encrypt some files, simply launch the tools provided later in this article.


This tool provides a text box to enter the file name and a text box to enter the key, providing encryption, decryption, and key generation capabilities through a convenient user interface. In figure one, the upper text box is used to enter the name of the file to be encrypted/decrypted, and the following text box is used to enter a 8-character password. After performing the encryption operation, a new file is generated, the encrypted file and the original file are in the same directory, the file name is the same as the original file, but the "xx" suffix is added, for example, if the original file is MyFile.txt, the encrypted file is MyFilexx.txt.

After the encryption is good, the original file may not be deleted, but generally it is best to delete, because the underlying purpose of encryption is to hide the original file data. If you want to recover the original file from the encrypted file, enter MyFilexx.txt in the text box above, and then provide the password, the Cryption tool will create a MyFile.txt file that is the same as the original file. In other words, cryption the "xx" behind the file name as a sign to solve the ciphertext.

Note: After encrypting the file, if you forget the password used to encrypt the file, it is impossible to recover the original file. Of course, this is related to the complexity of the password itself, in order to ensure the security of the file, it is better to use a more complex password, such as the use of mixed letters, numbers and special characters (such as "$" symbol, etc.).

. NET provides more than one encryption technology, but the main discussion in this article is symmetric encryption. Symmetric cryptography is also known as private key cryptography, which is characterized by the same key (actually the same algorithm) used for encryption and decryption, both the decryption party and the encryption party have the responsibility to secure the password (for public key, asymmetric encryption, there are two keys, one key is public, this is currently recognized as the most effective encryption technology, But in terms of speed is much slower than symmetric encryption algorithm.

In the official use. NET encryption class to encrypt a file, you must first generate a key from the user-supplied password. The key can be generated by the hash function, the hash function converts the user's password string into a set of meaningless data, which can be used as a key, and the original data is uniquely deformed during the encryption process.

For example, one way to encrypt data with a key is to add the ASCII code of the original data to the ASCII code of the key:

Key: AB = ascii:97, 98
Data: Merry = ascii:109, 101, 114, 114, 121



The ASCII code of this set of data is added to the ASCII code of the key (the key is reused if necessary) and the resulting encryption results are:

97 98 97 98 97
+109 +101 +114 +114 +121
206 199 211 212 218



For the same data, the hash algorithm always produces the same result (that is, the same hash algorithm always generates the same bit sequence for the same password). In fact, in the code provided in this article, use the. Net ComputeHash method of SHA1CryptoServiceProvider class can verify this, for example, for the same input parameter morph, the method always returns the following result at any time: 124,230, 93,253,197, 206,136,72. Therefore, if someone knows the password and the algorithm that generates the key, he can also easily calculate the key.

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.