Java MD5 String md52(String string)

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

Description

md

License

Apache License

Declaration

public static String md52(String string) 

Method Source Code


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

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

public class Main {
    public static String md52(String string) {
        if (string == null || string.trim().length() < 1) {
            return null;
        }//w w  w.  j  ava 2  s . c o  m
        try {
            return getMD52(string.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    private static String getMD52(byte[] source) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            StringBuffer result = new StringBuffer();
            for (byte b : md5.digest(source)) {
                result.append(Integer.toHexString((b & 0xf0) >>> 4));
                result.append(Integer.toHexString(b & 0x0f));
            }
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
}

Related

  1. md5(String value)
  2. md5(String value)
  3. md5(String value)
  4. md5(String... args)
  5. MD5(String... texts)
  6. MD5_HEX(String source)
  7. md5AsHexString(String text, String charset)
  8. md5Base64(String str)
  9. md5ByHex(String src)