Common encryption and decryption algorithms-MD5

Source: Internet
Author: User
Tags md5 encryption asymmetric encryption

First, MD5 encryption overview

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.MD5 is a non-symmetric encryption Algorithm (PS: Symmetric encryption is encrypted with the password and decryption password is the same, asymmetric encryption and decryption with the key is not the same)Reference connection: MD5 encryption

Second, Java implementation MD5 encryption and decryption

1, MAVEN introduced Apache Jar (not maven project, go online next jar manually introduced)

            <dependency>                <groupId>org.apache.commons</groupId>                <artifactid>commons-lang3 </artifactId>                <version>3.3.2</version>            </dependency>

2. MD5 Use code

 Packagecom.jd.test;Importorg.apache.commons.codec.digest.DigestUtils;Importjava.security.MessageDigest;/*** MD5 General class * *@authorHao make the world *@since2017.04.15 *@version1.0.0_1 **/ Public classMD5 {/*** MD5 Method * *@paramtext in plain text *@paramKey Key *@returnCiphertext *@throwsException*/     Public StaticString MD5 (string text, string key)throwsException {//the encrypted stringString Encodestr=digestutils.md5hex (text +key); System.out.println ("The string after MD5 is encrypted: encodestr=" +encodestr); returnEncodestr; }    /*** MD5 Verification method * *@paramtext in plain text *@paramKey Key *@paramMD5 Ciphertext *@returnTrue/false *@throwsException*/     Public Static BooleanVerify (string text, string key, String md5)throwsException {//verify based on the key passed inString Md5text =MD5 (text, key); if(Md5text.equalsignorecase (MD5)) {SYSTEM.OUT.PRINTLN ("MD5 validation Passed"); return true; }            return false; }}

Common Cryptographic Tool Reference links:

1, the common encryption and decryption algorithm-MD5

2, the common encryption and decryption algorithm-BASE64

3, the common encryption and decryption algorithm-des

4, the common encryption and decryption algorithm-aes

Common encryption and decryption algorithms-MD5

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.