Brief introduction to the message digest
The main feature of the Message digest algorithm is that the encryption process does not require secret key , and the encrypted data cannot be decrypted, only the same plaintext data is entered by the same message digest algorithm to obtain the same ciphertext. The message digest algorithm does not have the problem of key management and distribution, and is suitable for the same use on distributed networks. Because of the considerable amount of encryption calculations, the previous algorithm is often used only for encryption in the case of limited data volumes, such as when the computer's password is encrypted with an irreversible encryption algorithm . In recent years, with the rapid improvement of computer's same performance, the encryption speed is no longer a constraint to the development of this encryption technology , so the field of message digest algorithm is increasing. Now, the message digest algorithm is mainly applied in the field of "digital signature", as a digest algorithm for plaintext. The famous digest algorithm has RSA Company's MD5 algorithm and SHA-1 algorithm and its large number of variants. The bits returned by the message digest appear to be randomly hashed together. A large number of inputs can be used to verify the output is the same, generally, different inputs will have different output, and the output of the digest message can be verified by randomness. However, a summary is not really random, because the same algorithm for the same message two times the summary, the result is necessarily the same, and if it is really random, it can not be reproduced anyway. So the message digest is "pseudo-random."
predict the professional algorithm introduction, need to refer to professional books.
find the system-supported message digest algorithm
Package date0803;/** * Find the system-supported message digest algorithm */import Java.security.security;public class printmessagedigestalgorithmsavailable {public static void main (string[] args) {System.out.println ("--------- The message digest algorithm supported by the system has--------"); For (String s:security.getalgorithms ("MessageDigest")) { System.out.println (s);}} }
The supported algorithms are:
The message digest algorithm supported by the---------system has--------SHA-384SHA-224SHA-256MD2SHASHA-512MD5
gets the message digest of the thread creation
Package date0803;/** * Write a program to calculate the message digest of a file * use threads to facilitate batch computing of File message digest * @author ZZW922CN */import Java.io.fileinputstream;import J Ava.io.ioexception;import Java.security.digestinputstream;import Java.security.messagedigest;import Java.security.nosuchalgorithmexception;import Javax.xml.bind.datatypeconverter;public class FileDigestThread Extends Thread {private String filename;/** * * @param filename */public filedigestthread (String filename) {super (); t His.filename = filename;} /** * Thread Main method */@Overridepublic void run () {try {//File input stream FileInputStream FileInputStream = new FileInputStream (filename); /Specify the algorithm, create a single example of the message digest messagedigest instance = messagedigest.getinstance ("SHA");//messagedigest instance = Messagedigest.getinstance ("SHA-512");//messagedigest instance = messagedigest.getinstance ("SHA-384");// MessageDigest instance = messagedigest.getinstance ("SHA-256");//messagedigest instance = Messagedigest.getinstance (" SHA-224 ");//messagedigest instance = messagedigest.getinstance (" MD5 ");//messagedigeSt Instance = messagedigest.getinstance ("MD2");//Create a digest input stream that is created from a specific input stream and message digest to Digestinputstream Digestinputstream = new Digestinputstream (FileInputStream, instance);//reads bytes and updates the digest, then closes the stream while (Digestinputstream.read ()!=-1); Digestinputstream.close ();///When all data has been updated, call the digest () method to complete the hash calculation, return the byte array byte[] Digest = Instance.digest ();//Create a string constructor, Convenient string operation StringBuilder StringBuilder = new StringBuilder (filename); String algorithm = Instance.getalgorithm (); Stringbuilder.append ("(Algorithm:" +algorithm+ "):");// Converts a byte array into a string Stringbuilder.append (Datatypeconverter.printhexbinary (Digest));//Print Message Summary results System.out.println ( Stringbuilder.tostring ());} catch (IOException ex) {System.err.println (ex);} catch (NoSuchAlgorithmException ex) {System.err.println (ex);}}}
running an instance
Package Date0803;import Java.io.file;public class Test1 {public static void main (string[] args) {File file = new file ("E:\ \ Data Mining course ppt "); file[] Listfiles = File.listfiles ();//For files, use absolute path, easy to find for (file subfile:listfiles) {String Absolutepath = Subfile.getabsolutepath (); Thread filedigestthread = new Filedigestthread (Absolutepath); Filedigestthread.start ();}}}
Run Results
E:\ Data Mining Course ppt\4lang.pdf (Algorithm:sha): 175561e04f5a14de82a5557c0ea036831ea5633ae:\ Data Mining Course ppt\1intro.pdf ( Algorithm:sha): 0f8d1449ba7c195bf7aaadc1351ed02882f7b579e:\ Data Mining Course ppt\3prep.pdf (Algorithm:sha): C85278213c0d649355870e6d637d5198dd73b33be:\ Data Mining Course ppt\5desc.pdf (Algorithm:sha) : 58a7f200cddda44d09e1f5514c8aa279e3e6e3fee:\ Data Mining Course ppt\2dw.pdf (Algorithm:sha) : 15d08fd207c2a680a529c7c18d847cc455e2080ae:\ Data Mining Course ppt\7class.pdf (Algorithm:sha) : 61ceb6da12e75af81ee84b15cbe2e4d23782993be:\ Data Mining Course ppt\8clst.pdf (Algorithm:sha): B6afe6fc67ee89e89860b7cf13b9550b9dcdf4fee:\ Data Mining Course ppt\10appl.pdf (Algorithm:sha) : 8c6429d5a1db0d8ce4df8d9933c2a08fe0065976e:\ Data Mining Course ppt\6asso.pdf (Algorithm:sha) : 4d04780ebb487c1aa014c631a5e5cb5305e6ee31e:\ Data Mining Course ppt\9cmplx.pdf (Algorithm:sha): B135431328fdc5abc965c01b0fd126c21533f5eb
Get message digest using Java