How Java passwords implement MD5 encryption

Source: Internet
Author: User
Import Java.security.MessageDigest;
Import java.security.NoSuchAlgorithmException;
    
 Import Org.apache.log4j.Logger; /** * MD5 Cryptographic Processing/public class Passworddigester {private static Logger Logger = Logger.getlogger (passwor
    
    Ddigester.class);
    
    private static final String algorithm_md5 = "MD5"; /** * Encrypt the password with MD5 * @param pass the password to encryption * See more highlights of this column: Http://www.bianceng . cnhttp://www.bianceng.cn/programming/java/* @return Encryption String */public static string GetPassMD5 (S
        Tring Pass) {String keys = null;
            try {messagedigest MD = messagedigest.getinstance (ALGORITHM_MD5);
            if (pass = = null) {pass = "";
            } byte[] Bpass = pass.getbytes ("UTF-8");
Md.update (Bpass);
            Keys = new String (Md.digest (), "GBK");
        Keys = bytestohexstring (Md.digest ()); catch (NosuchalgorithMexception aex) {logger.error ("There is no" + algorithm_md5 + "algorithm!");} catch (Java.io.UnsupportedEncodingException Uex) {logger.error ("Can not encode the password-" + uex.getmess
        Age ());
    return keys; /** * Converts beye[to hexadecimal string * @param barray * @return * * public static final string byte
     Stohexstring (byte[] barray) {stringbuffer sb = new StringBuffer (barray.length);
     String stemp;
      for (int i = 0; i < barray.length i++) {stemp = integer.tohexstring (0xFF & Barray[i]);
      if (Stemp.length () < 2) {sb.append (0);
     } sb.append (Stemp.touppercase ());
  return sb.tostring ();
   public static void Main (string[] args) {String a = "qazwsx";
  System.out.println (GetPassMD5 (a)); }
}

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.