Java MD5 Encryption Tool class

Source: Internet
Author: User
Tags md5 encryption

1 ImportJava.math.BigInteger;2 Importjava.security.MessageDigest;3 Importjava.security.NoSuchAlgorithmException;4 5  Public classMd5utils {6     /**7 * encryption using MD5 algorithm8      */9      Public Staticstring MD5 (string plaintext) {Ten         byte[] Secretbytes =NULL; One         Try { ASecretbytes = messagedigest.getinstance ("MD5"). Digest ( - plaintext.getbytes ()); -}Catch(nosuchalgorithmexception e) { the             Throw NewRuntimeException ("No MD5 this algorithm!") "); -         } -String Md5code =NewBigInteger (1, secretbytes). toString (16);//16 binary digits -         //If the generated number is below 32 bits, the preceding 0 is required +          for(inti = 0; I < 32-md5code.length (); i++) { -Md5code = "0" +Md5code; +         } A         returnMd5code; at     } -  -      Public Static voidMain (string[] args) { -SYSTEM.OUT.PRINTLN (MD5 ("123")); -     } -  in}

Java MD5 Encryption Tool class

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.