Android MD5 Encode md5(final String s)

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

Description

Creates an md5 hash string from the string input

Parameter

Parameter Description
s String to be hashed

Declaration

public static final String md5(final String s) 

Method Source Code

//package com.java2s;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    /**//from   w  w  w. j  ava  2  s  .c  o  m
     * Creates an md5 hash string from the string input
     *
     * @param s  String to be hashed
     * @return
     */
    public static final 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(String s)
  2. md5(String s)
  3. md5(String str)
  4. md5(final String s)
  5. md5(final String s)
  6. md5Byte(String in)
  7. md5Byte(byte[] in)
  8. md5File(File file)
  9. md5Hex(String str)