Because the feature involved is data encryption. So, after the small partners in the query and testing, I also queried some information to summarize the commonly used data encryption algorithm.
The full name of the MD5 MD5 encryption algorithm is message-digest algorithm 5,MD5 transform any length of "string" into a large integer of 128bit, and it is an irreversible string transform algorithm, in other words, even if you see the source program and algorithm description, there is no The method transforms a MD5 value into the original string. Commonly used in the site registration when the password is encrypted and stored in the database, and then at the time of login to encrypt the password and the database encryption password to compare, if the correct login system, to a certain extent, to ensure that the user information security. Specifically how to implement the string encryption, we look at the following example:
1 static void Main (string[] args) 2 {3 String source = "Hello world!"; 4 using (MD5 Md5hash = MD5. Create ()) 5 {6 String hash = Getmd5hash (Md5hash, source); Encrypt the String 7 8 Console.WriteLine ("The MD5 hash of" + Source + "is:" + hash + "."); Output the encrypted string 9 Console.WriteLine ("Verifying the hash ..."); Validates the encrypted string by one-by-one if (Verifymd5hash (Md5hash, source, hash))//judgment is consistent 13 {Console.WriteLine ("The hashes is the same."); Console.readkey (); ("The Hashes Console.WriteLine") is not same. "); Console.readkey (); (+}), #region "MD5 Encryption", the static string Getmd5hash ( MD5 Md5hash, String input) 27 {28 29//Convert the input string to a byte array, and then compute the hash value. byte[] data = Md5hash.computehash (Encoding.UTF8.GetBytes (input)); 31 32//Create a new data collection byte 33//Create a string. StringBuilder Sbuilder = new StringBuilder (); 35 36//each byte of the hash data by the Ring 37//and a hexadecimal string format for each one. A-Z for (int i = 0; i < data. Length; i++) Sbuilder.append (Data[i]. ToString ("X2")); 41} 42 43//returns a hexadecimal string. Sbuilder.tostring return (); A. 52 #region "Verify that the encrypted characters are the same" and that the hash value of a string is verified by the #endregion. Verifymd5hash static bool (MD5 Md5hash, string input, string hash) 54 {55//hash input. Hashofinput string = Getmd5hash (Md5hash, input); 57 58//Create a comparison hash stringcomparer. StringComparer comparer = stringcomparer.ordinalignorecase; 60 if (0 = = comparer. Compare (Hashofinput, hash))//compare, similar to the password in the database at the time of login (+) to true; + (+)-Else The #endregion
The final output is: Des des is all called data Encryption Standard, that is, the encryption standards, is a key encryption using the block algorithm, the specific encryption principle we do not need to understand, will be used on the line. Take doctrine! The DES algorithm has three entry parameters: Key, Data, Mode. Where key is 7 bytes A total of 56 bits, is the working secret of the DES algorithm, data is 8 bytes 64 bits, is to be encrypted or decrypted, mode for des works, there are two kinds: encryption or decryption. See the following example (vb.net) for specific usage. RSA RSA algorithm is the first skill user data encryption can also be used for digital signature algorithm. It is easy to understand and operate, and very popular. However, the security of RSA has not been proved theoretically. It has gone through various attacks and has not been completely compromised so far. Because it is a large number of calculations, RSA's fastest case is also several times slower than DES, whether it is software or hardware implementation. Speed has been a drawback of RSA. Generally, only a small amount of data encryption is used. Summary: Data encryption is a required skill in the future, and data security is becoming more and more important. We should pay attention to it.
A brief analysis of Data encryption (MD5,DES,RSA)