MD5 Encryption--java

Source: Internet
Author: User
Tags md5 encryption

MD5
Message Digest algorithm MD5 (Chinese named message Digest Algorithm version fifth) is a hash function widely used in the field of computer security to provide integrity protection for messages. The algorithm's file number is RFC 1321 (R.rivest,mit Laboratory for computer science and RSA Data Security Inc. April 1992). MD5 is message-digest algorithm 5 (Information-Digest algorithm 5), which is used to ensure complete and consistent information transmission. is one of the widely used hashing algorithms (also translation digest algorithm, hashing algorithm), mainstream programming language has been widely MD5 implemented.  The calculation of data (such as Chinese characters) as another fixed length value is the basic principle of the hashing algorithm, and the predecessor of MD5 is MD2, MD3 and MD4. The MD5 algorithm has the following characteristics: 1, compressibility: Any length of data, calculated the length of the MD5 value is fixed. 2, easy to calculate: It is easy to calculate the MD5 value from the original data. 3, anti-modification: Any changes to the original data, even if only 1 bytes modified, the resulting MD5 value is very different. 4, strong anti-collision: known raw data and its MD5 value, it is very difficult to find a data with the same MD5 value (that is, falsification of data). MD5 's role is to allow bulk information to be "compressed" into a confidential format before signing a private key with a digital signature software (that is, converting an arbitrary-length byte string into a long hexadecimal string). In addition to MD5, among them the more famous are sha-1, Ripemd and Haval and so on. Java implementation Encryption in Java some login password encryption, need to use MD5 encryption technologyjava.security.MessageDigestThe MD5 class is used to provide an application with an information digest algorithm, such as an algorithm for the. The simple point is that it is used to generate hash codes. The information digest is a secure, one-way hash function that receives data of any size and outputs a fixed-length hash value.messagedigesTIt is instantiated and initialized through its getinstance series of static functions. MessageDigest objects by using the updatemethod to process the data. Can be called at any time resetmethod to reset the summary. Once all the data that needs to be updated has been updated, you should call digestmethod to complete the hash calculation and return the result. For a given number of update data, digestMethod can only be called once. digestAfter the method is called, the MessageDigest object is reset to its initial state.
The following is a cryptographic process code implementation based on the above messagedigest

     Public Staticstring GetMd5 (string pwd) {MessageDigest MD=NULL; Try{MD=messagedigest.getinstance ("MD5");        Md.update (Pwd.getbytes ()); } Catch(nosuchalgorithmexception e) {//TODO auto-generated Catch blockE.printstacktrace (); }        //returns the Big Data integer, the Go-string        return NewBigInteger (1, Md.digest ()). ToString (10); }

MD5 Encryption--java

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.