Android examples for java.security:Hash
get Bytes MD5 hash
//package com.java2s; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static String getBytesMD5(byte[] input) { return getBytesHash("MD5", input); }/*ww w . j av a2 s. c om*/ private static String getBytesHash(String algo, byte[] input) { MessageDigest md; try { md = MessageDigest.getInstance(algo); md.reset(); md.update(input); byte b[] = md.digest(); return binaryToHexString(b); } catch (NoSuchAlgorithmException e) { return String.valueOf(input.hashCode()); } } public static String binaryToHexString(byte[] messageDigest) { // Create Hex String StringBuffer hexString = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++) { int by = 0xFF & messageDigest[i]; if (by < 0x10) { hexString.append("0").append(Integer.toHexString(by)); } else if (by >= 0x10) { hexString.append(Integer.toHexString(by)); } } return hexString.toString(); } }