Simple Example of MD5 Encryption Algorithm

Source: Internet
Author: User
Tags md5 encryption
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

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.