Java MD5 String md5(String string)

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

Description

md

License

Open Source License

Declaration

public static String md5(String string) 

Method Source Code

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

import java.math.BigInteger;
import java.nio.ByteBuffer;

import java.nio.charset.StandardCharsets;

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

public class Main {
    public static String md5(String string) {
        return md5(StandardCharsets.UTF_8.encode(string));
    }//  w  w  w  .  j  a va2s .  c  o  m

    public static String md5(byte[] data) {
        return md5(ByteBuffer.wrap(data));
    }

    public static String md5(ByteBuffer data) {
        try {
            MessageDigest hash = MessageDigest.getInstance("MD5");
            hash.update(data);
            return String.format("%032x", new BigInteger(1, hash.digest())); // as hex string
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

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