Java MD5 String md5(String orgin)

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

Description

md

License

Open Source License

Declaration

public static String md5(String orgin) 

Method Source Code


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

import java.security.MessageDigest;

public class Main {

    public static String md5(String orgin) {
        try {// ww  w  .j  av  a  2 s  .c o  m
            MessageDigest md = MessageDigest.getInstance("MD5");
            String result = byte2hex(md.digest(orgin.toString().getBytes("utf-8")));
            return result;
        } catch (Exception e) {
            throw new java.lang.RuntimeException("sign error !");
        }
    }

    private static String byte2hex(byte[] b) {
        String hs = "";
        String stmp = "";
        for (int n = 0; n < b.length; n++) {
            stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
            if (stmp.length() == 1)
                hs = hs + "0" + stmp;
            else
                hs = hs + stmp;
        }
        return hs.toUpperCase();

    }
}

Related

  1. md5(String message)
  2. MD5(String message)
  3. MD5(String message)
  4. md5(String message)
  5. md5(String message)
  6. md5(String pass)
  7. md5(String password)
  8. md5(String password)
  9. md5(String password)