Java MD5 String md5(String data)

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

Description

md

License

Open Source License

Declaration

public static String md5(String data) throws NoSuchAlgorithmException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String md5(String data) throws NoSuchAlgorithmException {
        return byte2hex(MessageDigest.getInstance("MD5").digest(data.getBytes()));
    }//from   w  w  w  .  ja va 2 s. co  m

    public static String byte2hex(byte[] bytes) {
        BigInteger bi = new BigInteger(1, bytes);
        String hex = bi.toString(16);
        int paddingLength = (bytes.length * 2) - hex.length();
        if (paddingLength > 0) {
            return String.format("%0" + paddingLength + "d", 0) + hex;
        }
        return hex;
    }
}

Related

  1. md5(String d)
  2. md5(String data)
  3. md5(String data)
  4. md5(String data)
  5. md5(String data)
  6. md5(String encryptStr)
  7. MD5(String input)
  8. md5(String input)
  9. md5(String input)