Java MD5 String md5(String s)

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

Description

md

License

Open Source License

Declaration

public static String md5(String s) throws NoSuchAlgorithmException 

Method Source Code

//package com.java2s;
/*//from  w  w  w  .  j  a  v a  2 s. c  om
 * (C) 2007-2012 Alibaba Group Holding Limited.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 * Authors:
 *   leiwen <chrisredfield1985@126.com> , boyan <killme2008@gmail.com>
 */

import java.security.NoSuchAlgorithmException;

public class Main {
    public static String md5(String s) throws NoSuchAlgorithmException {
        String result = "";
        java.security.MessageDigest m = java.security.MessageDigest
                .getInstance("MD5");
        m.update(s.getBytes(), 0, s.length());
        byte[] bytes = m.digest();
        for (int i = 0; i < bytes.length; i++) {
            String vs = Integer.toHexString(bytes[i] & 0xff);
            if (vs.length() < 2) {
                vs = '0' + vs;
            }
            result += vs;
        }
        return result;
    }
}

Related

  1. md5(String s)
  2. md5(String s)
  3. md5(String s)
  4. md5(String s)
  5. md5(String s)
  6. md5(String s)
  7. md5(String s)
  8. md5(String s)
  9. md5(String sInput)