Java MD5 String md5(String text, String key)

Here you can find the source of md5(String text, String key)

Description

md

License

Apache License

Declaration

public static String md5(String text, String key) throws Exception 

Method Source Code


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

import java.security.MessageDigest;

public class Main {

    public static String md5(String text, String key) throws Exception {
        byte[] bytes = (text + key).getBytes("utf-8");

        MessageDigest messageDigest = MessageDigest.getInstance("MD5");
        messageDigest.update(bytes);/*  ww  w . j a v a  2  s . co m*/
        bytes = messageDigest.digest();

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < bytes.length; i++) {
            if ((bytes[i] & 0xff) < 0x10) {
                sb.append("0");
            }

            sb.append(Long.toString(bytes[i] & 0xff, 16));
        }

        return sb.toString().toLowerCase();
    }
}

Related

  1. MD5(String text)
  2. MD5(String text)
  3. md5(String text)
  4. md5(String text)
  5. md5(String text, String charset)
  6. md5(String txt)
  7. md5(String userPass)
  8. md5(String value)
  9. md5(String value)