MD5
MD5 is a message Digest algorithm 5 (Information Digest algorithm 5) to ensure complete and consistent information transmission. is one of the widely used hashing algorithms of computers (also known as digest algorithm, hash algorithm ), mainstream programming language has been widely MD5 implemented.
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, weak 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).
5, strong anti-collision: To find two different data, so that they have the same MD5 value, is very difficult
the brief description of the MD5 algorithm can be: MD5 with 512-bit grouping to process the input information, and each grouping is divided into 16 32-bit sub-groups, after a series of processing, the output of the algorithm is composed of four 32-bit groupings, the four 32-bit grouping cascade will generate a 128-bit hash value.
public static byte[] Encrypt (String str) throws NoSuchAlgorithmException {//MD5 object MessageDigest messagedigest based on MD5 algorithm = Messagedigest.getinstance ("MD5"); byte[] Srcdata = Str.getbytes (); Use Srcbytes Update summary md5.update (SRCDATA); Complete hash calculation, get result return md5.digest (); }
SHA
Secure Hash algorithm is primarily applicable to digital signature algorithms (digitally Signature standard DSS) defined in digital Signature Al Gorithm DSA). For messages that are less than 2^64 bits in length, SHA1 produces a 160-bit message digest.
SHA-1 is a Data Encryption algorithm, the idea of the algorithm is to receive a piece of clear text, and then in an irreversible way to convert it into a paragraph (usually smaller) ciphertext, can also be easily understood as a string of input code (called Pre-mapping or information), and convert them to a shorter length, A fixed number of bits of output sequence is the process of hashing values (also known as information digests or information authentication codes).
public static byte[] Encrypt (String str) throws NoSuchAlgorithmException {//MessageDigest object generated from Sha algorithm MessageDigest sha = Messagedigest.getinstance ("SHA"); byte[] Srcdata = Str.getbytes (); Use Srcbytes Update summary sha.update (SRCDATA); Complete hash calculation, get result return sha.digest (); }
Java encryption--abstract algorithm