List of usage examples for java.security MessageDigest update
public final void update(ByteBuffer input)
From source file:Main.java
public static byte[] createDigest(String passcode, long t1, double q1) throws IOException, NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(passcode.getBytes()); ByteBuffer bb = ByteBuffer.allocate(16); //8 bytes for long and double each bb.putLong(t1);/*w ww . jav a 2 s.c o m*/ bb.putDouble(q1); md.update(bb); return md.digest(); }
From source file:Main.java
public static String md5(String str) throws Exception { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(str.getBytes()); byte byteData[] = md.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); }//from w w w .j a v a2 s . com return sb.toString(); }
From source file:Main.java
public static String SHA256(String text) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(text.getBytes()); byte[] digest = md.digest(); return Base64.encodeToString(digest, Base64.DEFAULT); }
From source file:Main.java
public static String getMd5(String source) { try {/*from w w w.j a v a 2s . c o m*/ MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(source.getBytes()); BigInteger bi = new BigInteger(1, md5.digest()); return String.format("%032x", bi); } catch (Exception e) { return ""; } }
From source file:Main.java
/** * For hashing the master password//ww w. j a v a 2 s . com * * @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
private static String hashBytes(MessageDigest hash, byte[] bytes) { hash.update(bytes); byte[] digest = hash.digest(); StringBuilder builder = new StringBuilder(); for (int b : digest) { builder.append(Integer.toHexString((b >> 4) & 0xf)); builder.append(Integer.toHexString((b >> 0) & 0xf)); }/*from w ww .j a va 2s. c o m*/ return builder.toString(); }
From source file:Main.java
public static String getStringMD5(String str) { String value = null;/* w w w . ja v a2s. c o m*/ try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(str.getBytes()); BigInteger bi = new BigInteger(1, md5.digest()); value = bi.toString(16).toUpperCase(); } catch (Exception e) { e.printStackTrace(); } return value; }
From source file:Main.java
public static byte[] encrypt(String x) throws Exception { java.security.MessageDigest d = null; d = java.security.MessageDigest.getInstance("SHA-1"); d.reset();// w w w . ja v a 2 s . c o m d.update(x.getBytes()); return d.digest(); }
From source file:Main.java
public static String generateMd5Hash(String str) { try {/*from ww w. j ava 2 s . co m*/ MessageDigest m = MessageDigest.getInstance("MD5"); m.update(str.getBytes("UTF8")); byte s[] = m.digest(); String result = ""; for (int i = 0; i < s.length; i++) { result += Integer.toHexString((0x000000ff & s[i]) | 0xffffff00).substring(6); } return result; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String md5(String input) throws Exception { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(input.getBytes("UTF-8")); BigInteger hash = new BigInteger(1, md5.digest()); return String.format("%1$032X", hash); }