List of usage examples for java.security MessageDigest update
public final void update(ByteBuffer input)
From source file:Main.java
public static String md5(byte[] data) { try {// ww w . ja v a2 s .c o m MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.update(data); return bytesToHex(messageDigest.digest()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:com.constellio.app.modules.es.connectors.http.utils.DigestUtil.java
public static String digest(final byte[] content) throws NoSuchAlgorithmException { MessageDigest shaDigester = MessageDigest.getInstance("SHA"); shaDigester.update(content); byte[] shaDigest = shaDigester.digest(); String digestString = new String(Base64.encodeBase64(shaDigest)); return digestString; }
From source file:Main.java
public static String GetMd5(final String s) { try {/*from w w w .j av a 2 s.c om*/ final MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(s.trim().getBytes()); final byte[] messageDigset = digest.digest(); return Bytes2Hex(messageDigset); } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); } return s; }
From source file:Main.java
/** * Returns the Md5 hash for the given text. * /*w w w .ja va2 s .c o m*/ * @param text * String whose Md5 hash should be returned. * @return Returns the Md5 hash for the given text. */ public static String getMd5Hash(String text) { StringBuffer result = new StringBuffer(32); try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(text.getBytes()); Formatter f = new Formatter(result); byte[] digest = md5.digest(); for (int i = 0; i < digest.length; i++) { f.format("%02x", new Object[] { new Byte(digest[i]) }); } } catch (NoSuchAlgorithmException ex) { ex.printStackTrace(); } return result.toString(); }
From source file:Main.java
public static String md5(String str) { String cacheKey;/*from w w w . ja v a 2 s . c o m*/ try { final MessageDigest mDigest = MessageDigest.getInstance("MD5"); mDigest.update(str.getBytes()); cacheKey = bytesToHexString(mDigest.digest()); } catch (NoSuchAlgorithmException e) { cacheKey = String.valueOf(str.hashCode()); } return cacheKey; }
From source file:Main.java
public static final String md5(String tps) { final String MD5 = "MD5"; try {/*from ww w . ja v a 2 s.c o m*/ // Create MD5 Hash MessageDigest digest = MessageDigest.getInstance(MD5); digest.update(tps.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 ""; }
From source file:Main.java
/** * Encrypt the plain text with MD5 algorithm. * * @param plainText The plain text./*from w w w .jav a 2 s. com*/ * @return The Encrypt content. */ public static String md5Encrypt(String plainText) { try { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(plainText.getBytes(Charset.defaultCharset())); return new String(toHex(digest.digest())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String keyToHashKey(String key) { String cacheKey;//www . jav a 2 s . c o m try { final MessageDigest mDigest = MessageDigest.getInstance("MD5"); mDigest.update(key.getBytes()); cacheKey = bytesToHexString(mDigest.digest()); } catch (NoSuchAlgorithmException e) { cacheKey = String.valueOf(key.hashCode()); } return cacheKey; }
From source file:Main.java
public static String md5(final String s) { final String MD5 = "MD5"; try {/*from www . j a v a2s . c o 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 ""; }
From source file:Main.java
/** * Print hash key// w w w . j av a 2 s .c om */ public static void printHashKey(Context context) { try { PackageInfo info = context.getPackageManager().getPackageInfo(TAG, PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); String keyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT); Log.d(TAG, "keyHash: " + keyHash); } } catch (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } }