Android MD5 Encode MD5Crypto(String str)

Here you can find the source of MD5Crypto(String str)

Description

MD Crypto

Declaration

public static String MD5Crypto(String str) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static String MD5Crypto(String str) {
        try {//from www  .  jav  a  2 s .  c o  m
            // Create MD5 Hash
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(str.getBytes());
            byte messageDigest[] = digest.digest();
            return toHexString(messageDigest);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        return "";
    }

    private static String toHexString(byte[] b) { // String to byte
        char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
                '9', 'A', 'B', 'C', 'D', 'E', 'F' };

        StringBuilder sb = new StringBuilder(b.length * 2);
        for (int i = 0; i < b.length; i++) {
            sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]);
            sb.append(HEX_DIGITS[b[i] & 0x0f]);
        }
        return sb.toString();
    }
}

Related

  1. getMD5Str(String str)
  2. md5(String s)
  3. MD5(String s)
  4. MD5Crypto(String str)