Java MD5 String md5Hex(String message)

Here you can find the source of md5Hex(String message)

Description

md Hex

License

Open Source License

Declaration

static String md5Hex(String message) 

Method Source Code


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

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    static String md5Hex(String message) {
        String returnValue;//  w w  w .  j a v  a 2s .  c om
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            returnValue = hex(md.digest(message.getBytes("CP1252")));
        } catch (NoSuchAlgorithmException e) {
            returnValue = null;
        } catch (UnsupportedEncodingException e) {
            returnValue = null;
        }
        return returnValue;
    }

    private static String hex(byte[] array) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < array.length; ++i) {
            sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
        }
        return sb.toString();
    }
}

Related

  1. md5Hex(String data)
  2. md5Hex(String message)
  3. md5Hex(String message)
  4. md5Hex(String message)
  5. md5Hex(String message)
  6. md5Hex(String s)
  7. md5hex(String source)
  8. md5Hex(String str)
  9. md5raw(String data)