List of usage examples for java.lang Integer toHexString
public static String toHexString(int i)
From source file:Main.java
public static String generateMD5Hash(String textToBeHashed) { try {//from ww w . j ava2 s. co m MessageDigest messageDigest = MessageDigest.getInstance(MD5); messageDigest.update(textToBeHashed.getBytes()); byte[] messageDigestByte = messageDigest.digest(); StringBuffer MD5Hash = new StringBuffer(); String h; for (int i = 0; i < messageDigestByte.length; ++i) { h = Integer.toHexString((0xFF & messageDigestByte[i]) | 0x100).substring(1, 3); MD5Hash.append(h); } return MD5Hash.toString(); } catch (Exception e) { throw new RuntimeException("Couldn't generate MD5 hash for " + textToBeHashed); } }
From source file:Main.java
public static String md5(String s) { if (null == digest) return ""; // Create MD5 Hash digest.reset();/* ww w .j a v a 2s .c om*/ digest.update(s.getBytes()); byte messageDigest[] = digest.digest(); // Create Hex String StringBuffer hexString = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++) hexString.append(Integer.toHexString(0xFF & messageDigest[i])); return hexString.toString(); }
From source file:Main.java
public final static String MD5(String s) { try {//from w w w.j a va 2 s . co m byte[] btInput = s.getBytes(); MessageDigest mdInst = MessageDigest.getInstance("MD5"); mdInst.update(btInput); byte[] md = mdInst.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < md.length; i++) { int val = ((int) md[i]) & 0xff; if (val < 16) sb.append("0"); sb.append(Integer.toHexString(val)); } return sb.toString(); } catch (Exception e) { return null; } }
From source file:Main.java
/** * md5// w ww. j av a 2 s .c o m * * @param str * @return */ public static String md5(String str) { try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.reset(); messageDigest.update(str.getBytes("UTF-8")); byte[] byteArray = messageDigest.digest(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < byteArray.length; i++) { if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) { sb.append("0").append(Integer.toHexString(0xFF & byteArray[i])); } else { sb.append(Integer.toHexString(0xFF & byteArray[i])); } } return sb.toString(); } catch (Exception e) { e.printStackTrace(); } return str; }
From source file:Main.java
public static String getDeviceBssid(byte[] responseBytes) { int deviceBssidOffset = 0x0a; int deviceBssidCount = MAC_ADDR_LEN; StringBuilder sb = new StringBuilder(); for (int i = 0; i < deviceBssidCount; ++i) { if (i != 0) { sb.append(":"); }/*from w ww. j a va 2 s .c o m*/ int hexValue = 0xff & responseBytes[deviceBssidOffset + i]; if (hexValue < 0x0f) { sb.append("0"); } sb.append(Integer.toHexString(hexValue)); } return sb.toString(); }
From source file:Main.java
public static String md5(String s) { try {// ww w . ja va 2 s . c om // Create MD5 Hash MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(s.getBytes()); byte messageDigest[] = digest.digest(); // Create Hex String StringBuffer hexString = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++) { String h = Integer.toHexString(0xFF & messageDigest[i]); while (h.length() < 2) h = "0" + h; hexString.append(h); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String md5(final String string) { try {//w w w. j a v a 2s.c o m // Create MD5 Hash MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(string.getBytes()); byte messageDigest[] = digest.digest(); // Create Hex String StringBuilder hexString = new StringBuilder(); for (byte currentByte : messageDigest) { String h = Integer.toHexString(0xFF & currentByte); while (h.length() < 2) h = "0" + h; hexString.append(h); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static final String md5(final String s) { try {//from w ww.ja va 2 s .c o m // Create MD5 Hash MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(s.getBytes()); byte messageDigest[] = digest.digest(); // Create Hex String StringBuffer hexString = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++) { String h = Integer.toHexString(0xFF & messageDigest[i]); while (h.length() < 2) h = "0" + h; hexString.append(h); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
private static String bytesToHexString(byte[] bytes) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(0xFF & bytes[i]); if (hex.length() == 1) { sb.append('0'); }/* w ww.ja va 2 s . com*/ sb.append(hex); } return sb.toString(); }
From source file:Main.java
public static String md5(final String s) { final String MD5 = "MD5"; try {/*from w w w . j a v a2 s .co m*/ // Create MD5 Hash MessageDigest digest = 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 ""; }