Java MD5 String md5(String string)

Here you can find the source of md5(String string)

Description

md

License

Apache License

Declaration

public static String md5(String string) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String md5(String string) {
        StringBuffer sb = new StringBuffer();

        try {/*ww w .ja va2  s .co  m*/
            byte[] buf = string.getBytes();
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(buf);
            byte[] digestBuf = md5.digest();
            for (byte b : digestBuf) {
                sb.append(Integer.toHexString(b & 0xff));
            }
        } catch (NoSuchAlgorithmException e) {
            /*empty*/
        }

        return sb.toString();
    }
}

Related

  1. md5(String str)
  2. md5(String string)
  3. md5(String string)
  4. md5(String string)
  5. md5(String string)
  6. md5(String string)
  7. md5(String string)
  8. MD5(String string)
  9. md5(String strs)