Java MD5 Encode MD5Encode(String sourceString)

Here you can find the source of MD5Encode(String sourceString)

Description

MD Encode

License

Apache License

Declaration

public static String MD5Encode(String sourceString) 

Method Source Code


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

import java.security.MessageDigest;

public class Main {
    public static String MD5Encode(String sourceString) {
        String resultString = null;
        try {//from  w w  w  .  j a  v a2 s .  c  o  m
            resultString = new String(sourceString);
            MessageDigest md = MessageDigest.getInstance("MD5");
            resultString = byte2hexString(md.digest(resultString.getBytes()));
        } catch (Exception ex) {
        }
        return resultString;
    }

    public static final String byte2hexString(byte[] bytes) {
        StringBuffer buf = new StringBuffer(bytes.length * 2);
        for (int i = 0; i < bytes.length; i++) {
            if (((int) bytes[i] & 0xff) < 0x10) {
                buf.append("0");
            }
            buf.append(Long.toString((int) bytes[i] & 0xff, 16));
        }
        return buf.toString();
    }
}

Related

  1. MD5Encode(String origin)
  2. MD5Encode(String origin)
  3. MD5Encode(String s)
  4. Md5Encode(String source)
  5. md5Encode(String source)
  6. md5Encode(String src)
  7. MD5Encode(String str)
  8. md5Encode(String strPlain)
  9. MD5Encoder(String s, String charset)