Java MD5 String md5(String input)

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

Description

This method hashes whatever string is given to it in md5 DON'T use when cryptographic strength is important.

License

Mozilla Public License

Parameter

Parameter Description
input a parameter

Declaration

public static String md5(String input) 

Method Source Code

//package com.java2s;
//     The contents of this file are subject to the Mozilla Public License

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    /**/*from w ww  .  ja v  a  2s.c  om*/
     * This method hashes whatever string is given to it in md5
     * DON'T use when cryptographic strength is important.
     * @param input
     * @return
     */
    public static String md5(String input) {
        String result = input;
        if (input != null) {
            MessageDigest md;
            try {
                md = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException e) {
                throw new IllegalStateException(
                        "Can't find MD5 algorithm.", e);
            }
            md.update(input.getBytes());
            BigInteger hash = new BigInteger(1, md.digest());
            result = hash.toString(16);
            while (result.length() < 32) {
                result = "0" + result;
            }
        }
        return result;
    }
}

Related

  1. md5(String encryptStr)
  2. MD5(String input)
  3. md5(String input)
  4. md5(String input)
  5. md5(String input)
  6. md5(String input)
  7. md5(String Input)
  8. md5(String input)
  9. md5(String input)