Java MD5 String md5(final String s)

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

Description

md

License

Open Source License

Declaration

public static String md5(final String s) 

Method Source Code

//package com.java2s;
/**// w  w w  .jav  a 2s.co m
* @copyright Urucas
* @license   Copyright (C) 2013. All rights reserved
* @version   Release: 1.0.0
* @link       http://urucas.com
* @developers Bruno Alassia, Pamela Prosperi
*/

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

public class Main {
    public static String md5(final String s) {

        final String MD5 = "MD5";
        try {
            // Create MD5 Hash
            MessageDigest digest = java.security.MessageDigest.getInstance(MD5);
            digest.update(s.getBytes());
            byte messageDigest[] = digest.digest();

            // Create Hex String
            StringBuilder hexString = new StringBuilder();
            for (byte aMessageDigest : messageDigest) {
                String h = Integer.toHexString(0xFF & aMessageDigest);
                while (h.length() < 2)
                    h = "0" + h;
                hexString.append(h);
            }
            return hexString.toString();

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
}

Related

  1. md5(final String data)
  2. md5(final String inData)
  3. md5(final String input)
  4. md5(final String input)
  5. md5(final String message)
  6. md5(final String s)
  7. md5(final String str)
  8. md5(final String string)
  9. md5(final String string)