List of usage examples for java.security MessageDigest digest
public byte[] digest()
From source file:Main.java
private static byte[] getKeyBytes(String mykey) { try {/*from ww w . j a v a2 s . c o m*/ MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(mykey.getBytes(Charset.forName("UTF-8"))); return digest.digest(); } catch (NoSuchAlgorithmException e) { Log.e(TAG, "Password creation exception: " + e.toString()); return errorbyte; } }
From source file:Main.java
public static Bitmap createIdenticon(String data) { try {/* w w w .j av a2s. c om*/ MessageDigest dig = MessageDigest.getInstance("MD5"); dig.update(data.getBytes()); return createIdenticon(dig.digest()); } catch (NoSuchAlgorithmException e) { return null; } }
From source file:Main.java
public static String MD5(final String s) { final String MD5 = "MD5"; try {//from ww w .ja v a 2 s . c o m MessageDigest digest = java.security.MessageDigest.getInstance(MD5); digest.update(s.getBytes()); byte messageDigest[] = digest.digest(); 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
public static String makeSHA1Hash(byte[] bytes) { try {/*www . j a v a 2 s .com*/ MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(bytes, 0, bytes.length); byte[] sha1hash = md.digest(); return convertToHex(sha1hash); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static String getSHA256(byte[] mydata) { try {/*from w w w. ja v a 2s .c om*/ MessageDigest digest = java.security.MessageDigest.getInstance("SHA256"); digest.update(mydata); return bytesToHex(digest.digest()).toLowerCase(); } catch (NoSuchAlgorithmException e) { Log.e(TAG, "SHA hash exception: " + e.toString()); return null; } }
From source file:Main.java
/** * A hashing method that changes a string (like a URL) into a hash suitable * for using as a disk filename./*from w w w.j ava 2 s.com*/ */ public static String hashKeyForUrl(String key) { String cacheKey; 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 byte[] md5(String strObj) { MessageDigest md; try {/*from w w w .j a v a 2s . c om*/ md = MessageDigest.getInstance("MD5"); md.update(strObj.getBytes()); byte[] pwd = md.digest(); return pwd; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
/** * For hashing the master password//from ww w. j a va 2 s. c om * * @param password * @return */ public static String hashPassword(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(password.getBytes("UTF-8")); // Change this to "UTF-16" if needed byte[] digest = md.digest(); return new String(digest); }
From source file:Main.java
public static String md5_32(String plainText) { String re_md5 = new String(); try {/*from w w w . j ava 2 s . co m*/ MessageDigest md = MessageDigest.getInstance("MD5"); md.update(plainText.getBytes()); byte b[] = md.digest(); int i; StringBuffer buf = new StringBuffer(""); for (int offset = 0; offset < b.length; offset++) { i = b[offset]; if (i < 0) i += 256; if (i < 16) buf.append("0"); buf.append(Integer.toHexString(i)); } re_md5 = buf.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return re_md5; }
From source file:Main.java
public static String GetMd5(final String s) { try {/* w ww . j a v 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; }