A simple example of the MD5 encryption algorithm is now available for websites on the network. If the functions are slightly improved, you must register them, provide personal privacy information such as user name, user password, email, or even phone number, and detailed address before you can enjoy some special information or services provided by the website. To increase security, it is necessary to encrypt private data in the database.
The MD5 algorithm, namely "message-Digest algorithm 5 (Information-Digest algorithm)", is a one-way encryption algorithm developed by md2, md3, and md4, that is, the hash algorithm, R. rivest was developed in the early 1990s S. Currently, MD5 has been widely used in project practice.
There are two types of encryption algorithms: one-way encryption algorithm and two-way encryption algorithm. Bidirectional encryption is the most commonly used encryption algorithm. It encrypts plaintext data that can be directly understood into ciphertext data that cannot be directly understood. When necessary, some algorithms can be used to decrypt the encrypted ciphertext data into the original plaintext data. One-way encryption is the opposite. It can only encrypt the plaintext data, but cannot decrypt the encrypted ciphertext data into the original plaintext data.
The MD5 algorithm is a one-way encryption algorithm. It has two important features: First, any two segments of plaintext data, encrypted ciphertext data must be different, and second, any segment of plaintext data, after encryption, the ciphertext data is always the same.
Create a console application. Smallville is used to encrypt text.
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. security. cryptography; namespace md5test {class program {// public static string getmd5str (string mystring) {MD5 MD5 = new md5cryptoserviceprovider (); // obtain the character array byte [] fromdata = system. text. encoding. unicode. getbytes (mystring); // get the byte [] todata = md5.computehash (fromdata); string bytestr = NULL; For (INT I = 0; I <todata. length; I ++) {// returns the character array to a string in hexadecimal notation without leading "0x" bytestr + = todata [I]. tostring ("X");} return bytestr;} static void main (string [] ARGs) {string md5str = "Smallville"; string md5newstr = getmd5str (md5str); console. writeline (md5newstr); console. readline ();}}}
PS: The system. Security. cryptography namespace must be referenced. Output result:
Simple Example of MD5 Encryption Algorithm