Java MD5 String md5(String s)

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

Description

md

License

Open Source License

Declaration

public static String md5(String s) 

Method Source Code


//package com.java2s;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;

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

public class Main {
    private static MessageDigest digest;

    public static String md5(String s) {
        try {/*  w ww .java 2s. c  om*/
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] messageDigest = md.digest(s.getBytes("UTF-8"));
            BigInteger number = new BigInteger(1, messageDigest);
            String md5 = number.toString(16);
            while (md5.length() < 32)
                md5 = "0" + md5;
            return md5;
        } catch (NoSuchAlgorithmException e) {
            //TODO error handle
        } catch (UnsupportedEncodingException e) {
            //TODO error handle
        }
        return null;

    }
}

Related

  1. md5(String s)
  2. md5(String s)
  3. md5(String s)
  4. md5(String s)
  5. md5(String s)
  6. md5(String s)
  7. md5(String s)
  8. md5(String s)
  9. md5(String s)