Java MD5 Encode MD5Encoding(String source)

Here you can find the source of MD5Encoding(String source)

Description

MD Encoding

License

LGPL

Declaration

public static String MD5Encoding(String source) throws NoSuchAlgorithmException 

Method Source Code


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

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

public class Main {
    public static String MD5Encoding(String source) throws NoSuchAlgorithmException {
        MessageDigest mdInst = MessageDigest.getInstance("MD5");
        byte[] input = source.getBytes();
        mdInst.update(input);/*from  w  w w.  jav a 2s  . c o  m*/
        byte[] output = mdInst.digest();

        int i = 0;

        StringBuffer buf = new StringBuffer("");

        for (int offset = 0; offset < output.length; offset++) {
            i = output[offset];

            if (i < 0) {
                i += 256;
            }

            if (i < 16) {
                buf.append("0");
            }

            buf.append(Integer.toHexString(i));
        }
        return buf.toString();
    }
}

Related

  1. MD5Encode(String str)
  2. md5Encode(String strPlain)
  3. MD5Encoder(String s, String charset)
  4. md5encoding(String data)
  5. md5Encoding(String s)