Here we only write out the main method, and call the main method. Don't forget to package it.
- /**
- * Java. security. MessageDigest class implements encryption algorithms such as MD5 SHA.
- */
- Public static void MD5Test (){
- MessageDigest md = null;
- Try {
- Md = MessageDigest. getInstance ("MD5 ");
- } Catch (NoSuchAlgorithmException e ){
- E. printStackTrace ();
- }
- String s = "df9f"; // String to be encrypted
- System. out. println ("encrypted string:" + s );
- Md. update (s. getBytes (); // the MD5 encryption algorithm only encrypts the character array rather than the string to obtain the object to be encrypted.
- Byte [] bs = md. digest (); // performs encryption and returns a String Array
- For (byte B: bs ){
- System. out. print (B + "|"); // print out the encrypted character array
- }
- System. out. println ();
- StringBuffer sb = new StringBuffer ();
- For (int I = 0; I <bs. length; I ++) {// The byte array is converted into a hexadecimal string to form the final ciphertext.
- Int v = bs [I] & 0xff;
- If (v <16 ){
- Sb. append (0 );
- }
- Sb. append (Integer. toHexString (v ));
- }
- System. out. println ("encrypted string:" + sb );
- }
This is:
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1233212519-0.png "/>
This article is from the "orangle lzz notebook" blog, please be sure to keep this source http://lzzjava.blog.51cto.com/2554001/911086