Java MD5 String md5(String password)

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

Description

md

License

LGPL

Declaration

public static String md5(String password) 

Method Source Code

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

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import java.nio.charset.*;

public class Main {
    public static String md5(String password) {
        byte[] uniqueKey = password.getBytes(Charset.forName("UTF-8"));
        byte[] hash = null;

        try {//  ww w . j ava  2  s. c  o  m
            hash = MessageDigest.getInstance("MD5").digest(uniqueKey);
        } catch (NoSuchAlgorithmException e) {
            throw new Error("No MD5 support in this VM.");
        }

        StringBuilder hashString = new StringBuilder();
        for (int i = 0; i < hash.length; i++) {
            String hex = Integer.toHexString(hash[i]);
            if (hex.length() == 1) {
                hashString.append('0');
                hashString.append(hex.charAt(hex.length() - 1));
            } else {
                hashString.append(hex.substring(hex.length() - 2));
            }
        }
        return hashString.toString();
    }
}

Related

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