Java uses MD5 encryption to decrypt

Source: Internet
Author: User

MD5 Encryption and decryption

 PackageEndecrypt; Importjava.io.UnsupportedEncodingException; Importjava.security.MessageDigest; Importjava.security.NoSuchAlgorithmException; /*** Decrypted with MD5 encryption *@authorTFQ * @datetime 2011-10-13*/   Public classMd5util {/*** * MD5 to generate 32-bit MD5 code*/       Public Staticstring String2md5 (String inStr) {messagedigest MD5=NULL; Try{MD5= Messagedigest.getinstance ("MD5"); }Catch(Exception e) {System.out.println (e.tostring ());              E.printstacktrace (); return""; }          Char[] Chararray =Instr.tochararray (); byte[] ByteArray =New byte[Chararray.length];  for(inti = 0; i < chararray.length; i++) Bytearray[i]= (byte) Chararray[i]; byte[] Md5bytes =md5.digest (ByteArray); StringBuffer Hexvalue=NewStringBuffer ();  for(inti = 0; i < md5bytes.length; i++){              intval = ((int) Md5bytes[i]) & 0xFF; if(Val < 16) Hexvalue.append ("0");          Hexvalue.append (Integer.tohexstring (Val)); }          returnhexvalue.tostring (); }        /*** Encryption decryption algorithm performs one time encryption, two times decryption*/        Public Staticstring convertMD5 (String inStr) {Char[] A =Instr.tochararray ();  for(inti = 0; i < a.length; i++) {A[i]= (Char) (A[i] ^ ' t '); } String S=NewString (a); returns; }        //test the main function     Public Static voidMain (String args[]) {string S=NewString ("Tangfuqiang"); System.out.println ("Original:" +s); System.out.println ("After MD5:" +String2md5 (s)); System.out.println ("Encrypted:" +convertMD5 (s)); System.out.println ("Decrypted:" +convertMD5 (convertMD5 (s))); }  }  

Java uses MD5 encryption to decrypt

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.